Windows Forms GUI Thread Unresponsive

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

Guest

I wonder can anyone reccomment a solution to this problem.

Let me explain, I've services running on my system, my
application receives diagnostic messages from these services, what i want to
do is create an MDIChild window for each service that is sending messages.

Ok so far so good, but I get problems if one service is constantly sending
messages to it's window because, this window is very busy updating it's view,
hence because it's in the same thread at all other MDIChild windows and the
MDIParent window the whole application is unresponsive because this window
is too busy.

I did manage to get the Multithread MDI working and stable in a C++ ATL/WTL
application but it proved a heartache to say the least. I'd rather not go
down that road again.
Also
1) I don't have same level of control in c#
2) having mdiparent in a different thread is not really an option.

Anyone got an idea
Thanks in advance
Brian.
 
Hi Brian

You need to look at Control.Invoke/Control.BeginInvoke/Control.EndInvoke in
the documentation - essentially, you should run your service code on a worker
thread, then you need to marshal the data back onto the UI thread. If you
look at Chris Sells articles on MSDN on multithreading in the Wonders of
Windows Forms columns, that should get you started...(I guess this is the
follow up to the post about running forms on separate threads!)

HTH

Nigel Armstrong
 
Brian,

How is your service "sending messages to it's window", please elaborate.
I suppose you have several services and a Windows Forms application, do you
have a background thread listening for messages sent by your services?
If you do, how do you update the UI from this workerthread? Are you
correctly marhaling the calls to the UI using Control.BeginInvoke?

Willy.
 
Ni Neil,

You're quite right this post is a follow up to my previous posts.

The Control.Inovke is not really an option to me, it uses a ThreadPool
(indirectly) The thread pool can only run so many jobs at once, and some
framework classes use it internally, so I don't want to block it with a lot
of tasks.
So I'll use a different method of marshaling my data to the GUI thread.

However this is not really my problem, my problem is that all my Windows
(GUI windows) are running in the same thread so If one window is getting
loadsa messages with data to display then the GUI will become unresponsive.

Hope you understand my problem, I will have a thread (worker) that gets
messages from my windows services, this thread will send messages to my
MDIClient window,
problem is if all my MDIClients run on the GUI thead then all the
MDIClients, including the MDIParent will be unresponsive.

Hope this makes some bit of sence and thanks for your time.
Regards
Brian.


Thanks I'll have a read of the Chris Sells.
 
Hi Willy,
Yes I have a seperate worker thread receiving messages from my servies,
this message will basically be the ServiceName and the Information to display.

I will send this information to the new thread (havn't decided how yet but
not with Control.Inovke i think http://www.yoda.arachsys.com/csharp/threads/).

All this should not be a problem, my porblem appears when the gui thread is
trying to display the information in the window.

If all my windows are on the same thread it will cause all the windows to
become unresponsive (for examply if i try click close the application could
take along time to get the close messags because the window is too busy to
get messages off the windows message queue.

Actually I'm basing all this on a ATL/WTL application I once wrote and have
just assumed that I am going to have the same problems.

So I'm gonna finish reading
http://www.yoda.arachsys.com/csharp/threads/
and Chris Sells's articles and then create a sample application and see if I
really do have a problem or not.

Thanks for your time,
Regards.
Brian
 
<"=?Utf-8?B?QnJpYW4gS2VhdGluZyBFSTlGWEI=?=" <csharp at
briankeating.net> said:
You're quite right this post is a follow up to my previous posts.

The Control.Inovke is not really an option to me, it uses a ThreadPool
(indirectly)

No it doesn't. There's nothing to stop you from starting your own
threads, and then using Control.Invoke - no ThreadPool threads will be
involved.
However this is not really my problem, my problem is that all my Windows
(GUI windows) are running in the same thread so If one window is getting
loadsa messages with data to display then the GUI will become unresponsive.

Your UI shouldn't be doing so much work that it will ever be running
flat out - and if it does, then *something's* got to become
unresponsive. You should be doing as little as possible on the UI
thread.
Thanks I'll have a read of the Chris Sells.

You might also want to look at my threading article:
http://www.pobox.com/~skeet/csharp/threads/
 
Brian,

Your services and your Windows Forms application are separate applications
(processes) right? Please correct me if I'm wrong.
Question is "What IPC mechanism do you use to pass the messages from the
service to this UI application?"

Willy.
 
Hi again,

We've written our own IPC infrastructure for IPC messages. (basically
windows message queues).

So I'll have a receive thread that reads messages off the queue, then it
will send back to the windows thread.

Again my problem lies in that fact that if one service is sending alot of
messages (i.e. my receive thread is sending alot of messages to one window)
all other windows will become unresponsive bacause this window is eating up
the GUI threads resources trying to display all these messages.

so ideally i'd like each gui window to run in a seperate thread.... much
like a multithreaded sdi application, (winword for example).

However I'd really like it as an mdi application (which gives me more
problems)

So rounding up, it doesn't really matter how my services send the messages
to my GUIApplication.

Basically messages will be originate in my receiver thread (for my first
test i'm not even gonna read messages from the services i'm only gonna loop
sending messages to my gui thread) to my gui thread in my GUIApplication
itself.

I'm doing up a test prog at the moment so i'll let you know how i get on etc,

thanks for your time.
regards
Brian
 
Hi again,

We've written our own IPC infrastructure for IPC messages. (basically
windows message queues).

So I'll have a receive thread that reads messages off the queue, then it
will send back to the windows thread.

Again my problem lies in that fact that if one service is sending alot of
messages (i.e. my receive thread is sending alot of messages to one window)
all other windows will become unresponsive bacause this window is eating up
the GUI threads resources trying to display all these messages.

so ideally i'd like each gui window to run in a seperate thread.... much
like a multithreaded sdi application, (winword for example).

However I'd really like it as an mdi application (which gives me more
problems)

So rounding up, it doesn't really matter how my services send the messages
to my GUIApplication.

Basically messages will be originate in my receiver thread (for my first
test i'm not even gonna read messages from the services i'm only gonna loop
sending messages to my gui thread) to my gui thread in my GUIApplication
itself.

I'm doing up a test prog at the moment so i'll let you know how i get on etc,

thanks for your time.
regards
Brian
 
Back
Top