473,408 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Multithreading and applicantion hangs

Hi,

I am developing a Multithreaded Server based Task Scheduler wich runs
on the server and informs all the connected client when a particular
schedule occurs to do the assigned task.

Following is what I am doing to give you all an idea about the
application and how I have done it

I have a windows based application. This is a client which consists of
2 Forms viz Form1 and Form2 where Form1 is the main form and Form2 is
the form called by the application when the schdule occrs

I have Server (a dll) which has a main class called Class1 and another
class called Class2 which contains the information of each schedule.
The object of Class2 is started on each seperate thread by main the
object of main class as a worker thread. The Class2 has the
System.Timers.Timer (a server based timer) which got started when the
thread is started.

Now on each worker thread, when timer elasped it informs the main
class1 via delegate that a schedule has occured. The main class then
informs all the connected client that a schedule has occured. The the
Form1 gets this information it opens the Form2 and here is the problem.

When form1 tries to open the form2, the form2 hangs and doesn't show at
all. In the Task Manager it shows that the application is not
responding and then I have to kill the application.

Can anybody point out what could be going wrog or what is the wrong
thing which I am doing because of which such behaviour is shown.

Thanks

Prateek Baxi

Mar 8 '06 #1
4 1378
You may not access GUI components (including your form) from a worker
thread. You need to use Control.Invoke to marshal the call into the
correct thread.

Tom

pr*********@gmail.com wrote:
Hi,

I am developing a Multithreaded Server based Task Scheduler wich runs
on the server and informs all the connected client when a particular
schedule occurs to do the assigned task.

Following is what I am doing to give you all an idea about the
application and how I have done it

I have a windows based application. This is a client which consists of
2 Forms viz Form1 and Form2 where Form1 is the main form and Form2 is
the form called by the application when the schdule occrs

I have Server (a dll) which has a main class called Class1 and another
class called Class2 which contains the information of each schedule.
The object of Class2 is started on each seperate thread by main the
object of main class as a worker thread. The Class2 has the
System.Timers.Timer (a server based timer) which got started when the
thread is started.

Now on each worker thread, when timer elasped it informs the main
class1 via delegate that a schedule has occured. The main class then
informs all the connected client that a schedule has occured. The the
Form1 gets this information it opens the Form2 and here is the problem.

When form1 tries to open the form2, the form2 hangs and doesn't show at
all. In the Task Manager it shows that the application is not
responding and then I have to kill the application.

Can anybody point out what could be going wrog or what is the wrong
thing which I am doing because of which such behaviour is shown.

Thanks

Prateek Baxi


Mar 8 '06 #2
Don't ever call control methods and set properties from a thread different
than the one created the control. Of course there some that are safe to be
called, but as a rule of thumb don't do that. When you want to access
control form worker thread use Control.Invoke to marshal the code. In order
to find out where is ssafe to call a method or set a property you can use
Control's IsInvoleRequired property.

For more info:
http://msdn2.microsoft.com/en-us/library/ms171728.aspx
--
HTH
Stoitcho Goutsev (100)

<pr*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Hi,

I am developing a Multithreaded Server based Task Scheduler wich runs
on the server and informs all the connected client when a particular
schedule occurs to do the assigned task.

Following is what I am doing to give you all an idea about the
application and how I have done it

I have a windows based application. This is a client which consists of
2 Forms viz Form1 and Form2 where Form1 is the main form and Form2 is
the form called by the application when the schdule occrs

I have Server (a dll) which has a main class called Class1 and another
class called Class2 which contains the information of each schedule.
The object of Class2 is started on each seperate thread by main the
object of main class as a worker thread. The Class2 has the
System.Timers.Timer (a server based timer) which got started when the
thread is started.

Now on each worker thread, when timer elasped it informs the main
class1 via delegate that a schedule has occured. The main class then
informs all the connected client that a schedule has occured. The the
Form1 gets this information it opens the Form2 and here is the problem.

When form1 tries to open the form2, the form2 hangs and doesn't show at
all. In the Task Manager it shows that the application is not
responding and then I have to kill the application.

Can anybody point out what could be going wrog or what is the wrong
thing which I am doing because of which such behaviour is shown.

Thanks

Prateek Baxi

Mar 8 '06 #3
Typo. It should be Control.InvokeRequired. We knew what you meant
though :)

Stoitcho Goutsev (100) wrote:
Don't ever call control methods and set properties from a thread different
than the one created the control. Of course there some that are safe to be
called, but as a rule of thumb don't do that. When you want to access
control form worker thread use Control.Invoke to marshal the code. In order
to find out where is ssafe to call a method or set a property you can use
Control's IsInvoleRequired property.

For more info:
http://msdn2.microsoft.com/en-us/library/ms171728.aspx
--
HTH
Stoitcho Goutsev (100)


Mar 8 '06 #4
Prateek,

In addition to what others have said I usually prefer
Control.BeginInvoke. That way the worker won't block waiting for the
UI to process the message. Of course, it depends on the exact behavior
I'm after.

Brian

pr*********@gmail.com wrote:
Hi,

I am developing a Multithreaded Server based Task Scheduler wich runs
on the server and informs all the connected client when a particular
schedule occurs to do the assigned task.

Following is what I am doing to give you all an idea about the
application and how I have done it

I have a windows based application. This is a client which consists of
2 Forms viz Form1 and Form2 where Form1 is the main form and Form2 is
the form called by the application when the schdule occrs

I have Server (a dll) which has a main class called Class1 and another
class called Class2 which contains the information of each schedule.
The object of Class2 is started on each seperate thread by main the
object of main class as a worker thread. The Class2 has the
System.Timers.Timer (a server based timer) which got started when the
thread is started.

Now on each worker thread, when timer elasped it informs the main
class1 via delegate that a schedule has occured. The main class then
informs all the connected client that a schedule has occured. The the
Form1 gets this information it opens the Form2 and here is the problem.

When form1 tries to open the form2, the form2 hangs and doesn't show at
all. In the Task Manager it shows that the application is not
responding and then I have to kill the application.

Can anybody point out what could be going wrog or what is the wrong
thing which I am doing because of which such behaviour is shown.

Thanks

Prateek Baxi


Mar 8 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

47
by: mihai | last post by:
What does the standard say about those two? Is any assurance that the use of STL is thread safe? Have a nice day, Mihai.
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
5
by: sarge | last post by:
I would like to know how to perform simple multithreading. I had created a simple form to test out if I was multithreading properly, but got buggy results. Sometime the whole thig would lock up...
10
by: Ioannis Vranos | last post by:
In .NET multithreading we have to assign a thread to a method of a separate object each time (and not two methods of the same object)? In other words, why does this hung? #using...
2
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and...
5
by: sandy82 | last post by:
Whats actuallly multithreading is ... and how threading and multithreading differ . Can any1 guide how multithreading is used on the Web .. i mean a practical scenario in which u use...
7
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or...
3
by: =?ISO-8859-2?Q?Krzysztof_W=B3odarczyk?= | last post by:
Hi, I think I've found a bug in Python/C API and multithreading. I'm currently creating an intrusion detection system based on mobile agents. I have an AgentPlatform (C/C++) and 2 agents on...
0
by: waghmarerajendra | last post by:
I am working in .NET compact framework 1.1 and developing WINCE based application and running it on .NET emulator. I am developing an application where there is an UI and some background...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.