473,404 Members | 2,187 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,404 software developers and data experts.

When does a Windows Form create it's message processing thread

me
I have a Class Library that contains a Form and several helper classes. A
thread gets created that performs processing of data behind the scenes and
the Form never gets displayed (it is for debug puposes only and is not
normally visable to the user.) The Thread function is actually in the Form
class.

Now.. What I am seeing is that when I create an instance of this Class
Library's Form, which starts the worker thread, it seems to hose up the
displaying of the Form (it sees to be locked up) unless I place a
Application.DoEvents() call inside my worker threads function.

What this seems to tell me is that the thread I have created is blocking the
redrawing of the Form.. which doesnt make sense to me at all.

I have tried several ways to "resolve" this and here is what I have seen so
far:

1. DoEvents() in the Thread function seems to allow the Form to work
correctly.
2. Calling Show() and then Hide() of the Form before I start my worker
thread seems to allow me to then show and hide the Form later without any
problems.
3. If I do not show it and do not call DoEvents() then the Form does not
update when I perform a Show() later.

Any thoughts? I am almost thinking that the Form is not creating it's own
internal Message Handling thread until it is actually Show()'n and then when
it does it sees that I have a worker thread and attaches to it? Sounds
strange to me but that is what it looks like??

Any help would be appreciated.. You can email me at El******@hotmail.com
with any info you have.. I may not have access to this group later.....

Thx.

Jul 21 '05 #1
5 3570
Me,

When you have a from Form inherited form, than the form is showed directly
after (when you have that) the form load event. (When you don't make showing
in the contstructor or in that last event impossible of course).

I hope this helps?

Cor
Jul 21 '05 #2
Any thoughts? I am almost thinking that the Form is not creating it's own
internal Message Handling thread until it is actually Show()'n and then when
it does it sees that I have a worker thread and attaches to it? Sounds
strange to me but that is what it looks like??


There's no separate message handling thread. You need to call
Application.Run() on the thread you want to show UI to start the
message loop.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #3
As Mattias said, there is no separate UI thread created. The current
thread becomes the message handling thread once you call
Application.Run(). That's why calling DoEvents() on the current thread
seems to work.

Regards
Senthil

Jul 21 '05 #4
me
Just a test.. My last post has not shown up yet.. hmm...
"me" <me@home.com> wrote in message
news:a-********************@comcast.com...
I have a Class Library that contains a Form and several helper classes. A
thread gets created that performs processing of data behind the scenes and
the Form never gets displayed (it is for debug puposes only and is not
normally visable to the user.) The Thread function is actually in the Form
class.

Now.. What I am seeing is that when I create an instance of this Class
Library's Form, which starts the worker thread, it seems to hose up the
displaying of the Form (it sees to be locked up) unless I place a
Application.DoEvents() call inside my worker threads function.

What this seems to tell me is that the thread I have created is blocking
the
redrawing of the Form.. which doesnt make sense to me at all.

I have tried several ways to "resolve" this and here is what I have seen
so
far:

1. DoEvents() in the Thread function seems to allow the Form to work
correctly.
2. Calling Show() and then Hide() of the Form before I start my worker
thread seems to allow me to then show and hide the Form later without any
problems.
3. If I do not show it and do not call DoEvents() then the Form does not
update when I perform a Show() later.

Any thoughts? I am almost thinking that the Form is not creating it's own
internal Message Handling thread until it is actually Show()'n and then
when
it does it sees that I have a worker thread and attaches to it? Sounds
strange to me but that is what it looks like??

Any help would be appreciated.. You can email me at El******@hotmail.com
with any info you have.. I may not have access to this group later.....

Thx.

Jul 21 '05 #5
me
I tried to upload a sample but it has not shown up yet.. If you want to take
a look at the sample here is a link to it and instructions on how to
duplicate what I am seeing.

Link:
https://home.comcast.net/~cbcox/MsgLoopTest.zip

Instructions:
"MsgLoopTest.sln" should open up a solution with 2 projects (MsgLoopTest and
SampleLibrary). When you run it you should get a form that has 4 buttons on
it.

Create Form (Creates an instance of TestForm2 from the SampleLibray)
Show Form (direct call to Show() method of Form)
Create Thread (Creates a thread that resides in the TestForm2 code)
Set Show Form Flag (Sets a flag in the TestForm2 code that causes the Thread
to call Show()).

Here are two different ways to "Show" TestForm2.

This seems to work fine.. The form is displayed and it updates with no
problems.
1. Click Create Form
2. Click Show Form

This way does not seem to work unless you put a call to
Application.DoEvents() inside the thread proc.
1. Click Create Form
2. Click Create Thread
3. Click Set Show Form Flag

This way does seem to work but requires you to show and then hide the form
first via the Show Form button.
1. Click Create Form
2. Click Create Thread
3. Click Show Form
4. Click Hide on the TestForm2
5. Click Set Show Form Flag

Now the question/problem is why does this work this way? It seems like
whatever Thread calls Show() first takes ownership of the message loop
instead of the thread that actually created the instance of the form.


"me" <me@home.com> wrote in message
news:a-********************@comcast.com...
I have a Class Library that contains a Form and several helper classes. A
thread gets created that performs processing of data behind the scenes and
the Form never gets displayed (it is for debug puposes only and is not
normally visable to the user.) The Thread function is actually in the Form
class.

Now.. What I am seeing is that when I create an instance of this Class
Library's Form, which starts the worker thread, it seems to hose up the
displaying of the Form (it sees to be locked up) unless I place a
Application.DoEvents() call inside my worker threads function.

What this seems to tell me is that the thread I have created is blocking
the
redrawing of the Form.. which doesnt make sense to me at all.

I have tried several ways to "resolve" this and here is what I have seen
so
far:

1. DoEvents() in the Thread function seems to allow the Form to work
correctly.
2. Calling Show() and then Hide() of the Form before I start my worker
thread seems to allow me to then show and hide the Form later without any
problems.
3. If I do not show it and do not call DoEvents() then the Form does not
update when I perform a Show() later.

Any thoughts? I am almost thinking that the Form is not creating it's own
internal Message Handling thread until it is actually Show()'n and then
when
it does it sees that I have a worker thread and attaches to it? Sounds
strange to me but that is what it looks like??

Any help would be appreciated.. You can email me at El******@hotmail.com
with any info you have.. I may not have access to this group later.....

Thx.

Jul 21 '05 #6

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

Similar topics

4
by: Michael Kennedy [UB] | last post by:
Hi Everyone, I have this multithreaded C# windows forms application which does a lot of image processing. Occasionally, I get the following error: A generic error occurred in GDI+....
3
by: Shmulik | last post by:
I have an application written in C# that creates a queue of items to process, connects via a TCP connection to a server on a Unix box, and then passes data files to the Unix box for processing...
0
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
5
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
4
by: hzgt9b | last post by:
Using VB .NET 2003, I have a windows application that performs a series of file actions (copy, move, delete) but the actions are completing before the window is painted on the screen... how can I...
10
by: morangolds | last post by:
Hi, I've been having a problem with C++ Windows Forms apps not "ending" when you close the form window. I've searched about this problem all over the place and most searches have lead me to...
4
by: grayaii | last post by:
Hi, I have a simple form that handles all its paint functionality like so: this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); And the entry point to this...
2
by: abid gee | last post by:
Please give a kind look on my question. and please comments. I am Using C# as development tool of Dot Net 2.0. I wrote a function read_data() that read data from Serial Port continuously.Till...
2
by: Bill Davidson | last post by:
All: I have a Win32 service that takes about 30 seconds to shutdown (give or take a few seconds). I shut the service down via the 'Services' console on Windows Server 2003. When the service...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...

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.