473,320 Members | 1,535 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,320 software developers and data experts.

Messagebox oddity with multiple threads

When returning from a multithread callback, I've wrapped my code up
with:
if (MainForm.InvokeRequired)
MainForm.Invoke(CallStart,new object[]{BusinessCaller});
else
CallStart(BusinessCaller);

But even so, a Messagebox.show inside the delegate will sometimes be
modal to MainForm and sometimes happily allow me to switch back and
forth between the two.

If I _always_ do the MainForm.Invoke then it's always modal - but I'm
sure I've read somewhere that this is a bad idea.

Can anyone suggest why InvokeRequired might be coming back with the
wrong value?

Andy D

Nov 17 '05 #1
2 1506
Got somewhere further!

It doesn't matter I'm in the right thread or not!

With the following code, if my app is active when the messagebox pops
up, then it's modal. If I have another app active, then it's not
modal. This makes no sense to me at all!

private void button1_Click(object sender, System.EventArgs e)
{
BlankDelegate waitABit = new BlankDelegate(WaitABit);
ThreadStart t = new ThreadStart(waitABit);
Thread n = new Thread(t);
n.Start();
}

public void WaitABit()
{
Thread.Sleep(5000);
TestMessage();
}

public void TestMessage()
{
if (this.InvokeRequired)
{
BlankDelegate testMessage = new BlankDelegate(TestMessage);
this.Invoke(testMessage,null);
}
else
MessageBox.Show("Here we are");
}

delegate void BlankDelegate();

Nov 17 '05 #2
"Andrew Ducker" <an****@ducker.org.uk> wrote:
MessageBox.Show("Here we are");


Try the version of Show that takes a Form parameter, and pass your
form to it.

P.
Nov 17 '05 #3

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

Similar topics

8
by: Kris Caselden | last post by:
I noticed a strange yet easily fixed problem in Python's thread module. Consider the following code: #------------------------------- import thread data='this is data'
2
by: Ray Cassick \(Home\) | last post by:
I have been beating myself up over trying to locate what I thought was a memory leak in MY code but based upon what I have seen I can't be sure that it IS my fault or something strange with DOTNET....
0
by: alex_f_il | last post by:
The class centers MessageBox inside the parent rectangle. Enjoy! using System; using System.Windows.Forms; using System.Text; using System.Drawing; using System.Runtime.InteropServices; ...
2
by: Tumurbaatar S. | last post by:
ASP.NET QuickStart Tutorial says that: .... ASP.NET maintains a pool of HttpApplication instances over the course of a Web application's lifetime. ASP.NET automatically assigns one of these...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
2
by: Brett | last post by:
What are the advantages/disadvantages of using one process with multiple threads or doing the same task with multiple processes, each having one thread? I see using multiple threads under one...
2
by: Nuno Magalhaes | last post by:
Why does the MessageBox.Show function in the thread below changes the program behaviour, in other words, the APListView becomes filled with values with a call to RefreshAPListView. Without the...
3
by: Earl | last post by:
Relatively new to C# and I have an odd situation. When I show a messagebox when catching an exception, the message shows briefly then disappears. private void PopulateBrands() { SqlConnection...
35
by: keerthyragavendran | last post by:
hi i'm downloading a single file using multiple threads... how can i specify a particular range of bytes alone from a single large file... for example say if i need only bytes ranging from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.