473,811 Members | 3,021 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multithread and MessageBox

We have developed a CSharp program that has a secondary thread that is
used to perform background operations. This secondary thread may
display some MessageBoxes or Forms.

However, if the secondary thread is aborted, then the MessageBox
control does not get deleted. The forms do. I am unsure why this
should be the case because MessageBox is also derived from
System.Windows. Forms.

Is there any way I can get the MessageBoxes to be deleted when I abort
the secondary thread??
Nov 15 '05 #1
4 2815
I would change this around a bit. Your second thread should not have any UI
elements. It will just be a free thread that does its thing and calls
Invoke on a Windows form/control to allow *it to handle the message boxes or
put up other forms, etc. Your working thread can also check for a canceled
flag property in the loop and exit when true.
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003 JUL.1033/cpguide/html/cpcondeveloping m
ultithreadedwin dowsformscontro l.htm

--
William Stacey, MVP

"Mystery Man" <Pr************ @hotmail.com> wrote in message
news:87******** *************** ***@posting.goo gle.com...
We have developed a CSharp program that has a secondary thread that is
used to perform background operations. This secondary thread may
display some MessageBoxes or Forms.

However, if the secondary thread is aborted, then the MessageBox
control does not get deleted. The forms do. I am unsure why this
should be the case because MessageBox is also derived from
System.Windows. Forms.

Is there any way I can get the MessageBoxes to be deleted when I abort
the secondary thread??

Nov 15 '05 #2
"William Stacey" <st***********@ mvps.org> wrote in message news:<Og******* *******@tk2msft ngp13.phx.gbl>. ..
I would change this around a bit. Your second thread should not have any UI
elements. It will just be a free thread that does its thing and calls
Invoke on a Windows form/control to allow *it to handle the message boxes or
put up other forms, etc. Your working thread can also check for a canceled
flag property in the loop and exit when true.
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003 JUL.1033/cpguide/html/cpcondeveloping m
ultithreadedwin dowsformscontro l.htm

--
William Stacey, MVP

"Mystery Man" <Pr************ @hotmail.com> wrote in message
news:87******** *************** ***@posting.goo gle.com...
We have developed a CSharp program that has a secondary thread that is
used to perform background operations. This secondary thread may
display some MessageBoxes or Forms.

However, if the secondary thread is aborted, then the MessageBox
control does not get deleted. The forms do. I am unsure why this
should be the case because MessageBox is also derived from
System.Windows. Forms.

Is there any way I can get the MessageBoxes to be deleted when I abort
the secondary thread??


Thanks William, Changing it around as you suggest is not an easy
option for us. I have also read this article on multithreaded stuff.

Basically, the threading works like a charm for us and I really dont
want to do an overhaul as you suggest just to get a messageBox to
disappear.

Do you (or anyone else) have any other ideas?
Nov 15 '05 #3
Maybe I did not explain that fully. I am not suggesting big changes here.
Use your threads as is, just take the message box out of the worker thread
and put in a form method which gets called with the Invoke method. Pretty
minor unless I missed something. Handle all UI elements in your form. This
can have other benefits. Your message box can be tied to the form as the
owner, you can get a clean shutdown/canel mechanizum for your free thread
without it having spurious UI elements which can cause issues with not clean
shutdowns, and your thread will just do the right thing when the form exits
and can't just hang around (unless it is stuck on something.) Then again,
you know your code best, but that is one approach.

--
William Stacey, MVP

"Mystery Man" <Pr************ @hotmail.com> wrote in message
news:87******** *************** ***@posting.goo gle.com...
"William Stacey" <st***********@ mvps.org> wrote in message

news:<Og******* *******@tk2msft ngp13.phx.gbl>. ..
I would change this around a bit. Your second thread should not have any UI elements. It will just be a free thread that does its thing and calls
Invoke on a Windows form/control to allow *it to handle the message boxes or put up other forms, etc. Your working thread can also check for a canceled flag property in the loop and exit when true.
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003 JUL.1033/cpguide/html/cpcondeveloping m ultithreadedwin dowsformscontro l.htm

--
William Stacey, MVP

"Mystery Man" <Pr************ @hotmail.com> wrote in message
news:87******** *************** ***@posting.goo gle.com...
We have developed a CSharp program that has a secondary thread that is
used to perform background operations. This secondary thread may
display some MessageBoxes or Forms.

However, if the secondary thread is aborted, then the MessageBox
control does not get deleted. The forms do. I am unsure why this
should be the case because MessageBox is also derived from
System.Windows. Forms.

Is there any way I can get the MessageBoxes to be deleted when I abort
the secondary thread??


Thanks William, Changing it around as you suggest is not an easy
option for us. I have also read this article on multithreaded stuff.

Basically, the threading works like a charm for us and I really dont
want to do an overhaul as you suggest just to get a messageBox to
disappear.

Do you (or anyone else) have any other ideas?

Nov 15 '05 #4
Thanks again William. this would mean a bit of work as we run the same
engine from the main thread and from a secondary thread. In addition,
we have numerous message boxes (and forms) called from this engine.

Bear in mind that the reason why this secondary thread is initiated is
so that the user can suspend what they were doing (in the second
thread) and jump back to the main thread application. If we put the
message boxes into the main thread. then they would have to respond to
the message box before they can get access to other forms in the main
form (I think). This is not what we want. We want the users to get
access to the rest of the application ASAP, ie hit a suspend button
(on the second thread) and go straight back to the main thread).

Again, all I awnt to do is close down the message boxes that get shown
in the second thread when this gets aborted. I presume I could do a
PostMessage (or something like that??).
"William Stacey" <st***********@ mvps.org> wrote in message news:<#C******* *******@tk2msft ngp13.phx.gbl>. ..
Maybe I did not explain that fully. I am not suggesting big changes here.
Use your threads as is, just take the message box out of the worker thread
and put in a form method which gets called with the Invoke method. Pretty
minor unless I missed something. Handle all UI elements in your form. This
can have other benefits. Your message box can be tied to the form as the
owner, you can get a clean shutdown/canel mechanizum for your free thread
without it having spurious UI elements which can cause issues with not clean
shutdowns, and your thread will just do the right thing when the form exits
and can't just hang around (unless it is stuck on something.) Then again,
you know your code best, but that is one approach.

--
William Stacey, MVP

"Mystery Man" <Pr************ @hotmail.com> wrote in message
news:87******** *************** ***@posting.goo gle.com...
"William Stacey" <st***********@ mvps.org> wrote in message

news:<Og******* *******@tk2msft ngp13.phx.gbl>. ..
I would change this around a bit. Your second thread should not have any UI elements. It will just be a free thread that does its thing and calls
Invoke on a Windows form/control to allow *it to handle the message boxes or put up other forms, etc. Your working thread can also check for a canceled flag property in the loop and exit when true.
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003 JUL.1033/cpguide/html/cpcondeveloping m ultithreadedwin dowsformscontro l.htm

--
William Stacey, MVP

"Mystery Man" <Pr************ @hotmail.com> wrote in message
news:87******** *************** ***@posting.goo gle.com...
> We have developed a CSharp program that has a secondary thread that is
> used to perform background operations. This secondary thread may
> display some MessageBoxes or Forms.
>
> However, if the secondary thread is aborted, then the MessageBox
> control does not get deleted. The forms do. I am unsure why this
> should be the case because MessageBox is also derived from
> System.Windows. Forms.
>
> Is there any way I can get the MessageBoxes to be deleted when I abort
> the secondary thread??


Thanks William, Changing it around as you suggest is not an easy
option for us. I have also read this article on multithreaded stuff.

Basically, the threading works like a charm for us and I really dont
want to do an overhaul as you suggest just to get a messageBox to
disappear.

Do you (or anyone else) have any other ideas?

Nov 15 '05 #5

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

Similar topics

12
8624
by: haptiK | last post by:
Hello, can i use php to multithread mail() or something similar? in my company i need to send multiple copies of email to a few hundred ppl affilated and on my list. instead of calling mail over and over again i would like to thread this process. could someone point me to some documentation or perhaps an example of
0
1619
by: Alice | last post by:
Hello I have four multithread windows applications(vb.net) interacting and running on the same machine(windows 2000 with .net framework 1.0). All of them start a new thread each time Filewatcher's created or deleted event is fired. One of these application writes data into word documents also in multithread fashion. Sometimes the created and the deleted events of FileWatcher are not fired in one application - not the same one each time. Any...
0
1868
by: r_obert | last post by:
Hello, I'm trying to create a worker thread for my VC++ program, and was wondering whether I should be linking with the Multithread /MT or Multithread DLL /MD option? I'm not quite sure, in layman's terms, what the difference is. When I build with Multithread DLL, the linker complains about not being able to find a bunch of "unresolved external symbols" associated with nafxcwd.lib.
4
7093
by: zbcong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1"); private IPEndPoint myServer; private Socket socket; private Socket accSocket; private System.Windows.Forms.Button button2;...
2
26522
by: zhebincong | last post by:
Hello: I write a multithread c# socket server,it is a winform application,there is a richtextbox control and button,when the button is click,the server begin to listen the socket port,waiting for a incoming connection,the relative code snipprt as following:: private IPAddress myIP=IPAddress.Parse("127.0.0.1");
0
1319
by: fred | last post by:
I need some help in trying to understand how to make myCollection (inherited from CollectionBase) multithread safe. Taking my implementation of the Add Sub and a readonly property Item. Public Sub Add(ByVal aDoc As myDocument) List.Add(aDoc) End Sub Can I make this multithread safe by and is this the best way to do it.
6
2826
by: jmartin | last post by:
Hi, I have made a multithread version of a program (load a file into database), and with two processors I get the double of time in the multithread than in the process (unithread) version. I have done the test of creating a unique thread that does the same code that the process version of the program and it takes more time that the process without creating the thread.
2
5310
by: tikcireviva | last post by:
Hi Guys, I've done a mulithread queue implementation on stl<queue>, my developement environment is on VC6 as well as FC3. Let's talks about the win32 side. The suspected memory leak is find after I've run through my unit test cases. Test Case:
0
979
by: zektor | last post by:
Hi there, I have an application that have 1 backgroundworker doing operation in hw through rs232 (like a pooling constantly). In my UI thread I have do operations also on that resource (rs232 resource). The problem: When I click a button to send data over th rs232 and the worker is doing Some operation (backWorker.IsBusy == true) I send a cancelAsync to the worker, but I have to wait to perform operations. I try to sleep the current UI...
0
9727
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10133
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.