Home All Groups Group Topic Archive Search About

Treading for console applications in VB.NET

Author
12 Jun 2006 2:49 PM
fdmaxey
I have used threading in Windows applications successfully.  I am trying
to write a console application using synchronized threads, as I don't
need any display or operator interface.

However, when I call Monitor.Wait on any thread created, an exception is
thrown with the following description:

"Object synchronization method was called from an unsynchronized block
of code."

I've searched for any statement on this, but there is nothing definitive
that says threading in a console application is not allowed.  Some of
the code samples imply a console app.

Is threading (or at least synchronizing threads) simply not possible in
a console application?


Frank Maxey

*** Sent via Developersdex http://www.developersdex.com ***

Author
12 Jun 2006 3:49 PM
Brian Gideon
Frank,

Monitor.Wait can only be called with the thread currently owns the
lock.  That means a previous call to Monitor.Enter (or by using the
SyncLock keyword) has occurred.

Brian

fdmaxey wrote:
Show quoteHide quote
> I have used threading in Windows applications successfully.  I am trying
> to write a console application using synchronized threads, as I don't
> need any display or operator interface.
>
> However, when I call Monitor.Wait on any thread created, an exception is
> thrown with the following description:
>
> "Object synchronization method was called from an unsynchronized block
> of code."
>
> I've searched for any statement on this, but there is nothing definitive
> that says threading in a console application is not allowed.  Some of
> the code samples imply a console app.
>
> Is threading (or at least synchronizing threads) simply not possible in
> a console application?
>
>
> Frank Maxey
>
> *** Sent via Developersdex http://www.developersdex.com ***
Author
12 Jun 2006 7:43 PM
fdmaxey
That worked.  Thank you.

Frank Maxey

*** Sent via Developersdex http://www.developersdex.com ***