MultiThread problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everybody

I'm going crazy with this..
I'm developing an application for WM2003 with VS.NET 2003 and C#

In my application, in a form that is not the beginning form (where the "Main" function is), I start a secondary thread that should periodically update the GUI. To do this I use "Invoke" to call the right function in the main thread
The problem is that while the thread does its things, asynchronous user interaction with the GUI is possible. When the thread invokes the function of the main thread, if a user interaction occurs it crashes the application. A typical interaction is the use of the scroll bar

I think that the problem is that while the invoked function is executing, the application tries to execute the function associated to the Scroll Bar (these two functions are implemented in the same class): that is tha application tries to execute two different functions of the same class at the same time --> crash

Which could be a possible solution? Could MessageWindow solve it
I think that if I could manage the order of the messages that are executed by my application, I could solve it. Am I right? The problem is that I don't have any idea on how to do it..

Thank you fo your help

Stefan
 
Stefano,

What does the invoked function do?
--
Ginny Caughey
..Net Compact Framework MVP

Stefano said:
Hi everybody!

I'm going crazy with this...
I'm developing an application for WM2003 with VS.NET 2003 and C#.

In my application, in a form that is not the beginning form (where the
"Main" function is), I start a secondary thread that should periodically
update the GUI. To do this I use "Invoke" to call the right function in the
main thread.
The problem is that while the thread does its things, asynchronous user
interaction with the GUI is possible. When the thread invokes the function
of the main thread, if a user interaction occurs it crashes the application.
A typical interaction is the use of the scroll bar.
I think that the problem is that while the invoked function is executing,
the application tries to execute the function associated to the Scroll Bar
(these two functions are implemented in the same class): that is tha
application tries to execute two different functions of the same class at
the same time --> crash!
Which could be a possible solution? Could MessageWindow solve it?
I think that if I could manage the order of the messages that are executed
by my application, I could solve it. Am I right? The problem is that I don't
have any idea on how to do it...
 
Hi,

I think that you will have to delegate the interaction from the worker
thread to the UI thread using Control.Invoke. You must "marshal" changes to
the UI that are initiated by the worker thread so that they don't interfere
with the STAThread operation of the UI.

There are a number of messages here that relate to this. A recent on is
titled "Threads and Events."

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
Hi

in the secondary thread I call ".Invoke" invoking a function implemented in the main thread
I use the method described in "http://samples.gotdotnet.com/quickstart/CompactFramework/" to pass parameters on a thread in CompactFramework

Then my code is like

// in the main threa

ControlInvoker invoker = new ControlInvoker(this)

...

private void MyFunction(object arguments[]

//update HM


// in the secondary threa

invoker.Invoke(new MethodCallInvoker(this.MyFunction), object_1)


Hope this helps to help me... :-)

Thank yo

Stefan
 
The Invoke call should be made on one of the controls in your
application--I'm not sure if what you're doing will have the same effect.
For example, if your main form takes an event from a non-GUI thread, you
have to call:

this.Invoke( ... )

to get everything going in the right place. Unless your ControlInvoker is
doing this, it might not work.

Hope this helps,

Ryan

This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top