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

Creating a new message loop for a second form.

I have am still learning C#, so please bear with me.

I have an application that needs to open a second form, but I need the
second form to process message loops, whilst the original form also
continues to process message loops.

At the moment, my second form contains this code (and more irrelevant
code not listed)

public class SecondForm : System.Windows.Forms.Form
protected static void run()
{
Application.Run(SecondForm);
}
class SecondForm()
{
// Do something
}
}

From the first form, I'm attempting to open the second form simply
with

{
// This piece of code is already running in a second thread
// because it's doing something time consuming and I don't
// want the GUI to appear to hang.
SecondForm mySecondForm = new SecondForm();
mySecondForm.Show();
}

This opens the second form, but the second form doesn't process
message loops. When the SecondForm closes, I receive a
System.ObjectDisposedException on the line immediately after the
'mySecondForm.Show();' line.
Can anybody suggest what I'm doing wrong?
Nov 16 '05 #1
2 5026
You're almost there, but I don't see any code that calls your
SecondForm.run() method. Basically, all you need to do is to execute the
following in your new thread:

Application.Run(new SecondForm());

Just keep in mind that the Application.Run() call won't return until the
form is closed, so don't put any code after it expecting it to execute right
away.

Ken
"bryhhh" <br*********@gmail.com> wrote in message
news:91*************************@posting.google.co m...
I have am still learning C#, so please bear with me.

I have an application that needs to open a second form, but I need the
second form to process message loops, whilst the original form also
continues to process message loops.

At the moment, my second form contains this code (and more irrelevant
code not listed)

public class SecondForm : System.Windows.Forms.Form
protected static void run()
{
Application.Run(SecondForm);
}
class SecondForm()
{
// Do something
}
}

From the first form, I'm attempting to open the second form simply
with

{
// This piece of code is already running in a second thread
// because it's doing something time consuming and I don't
// want the GUI to appear to hang.
SecondForm mySecondForm = new SecondForm();
mySecondForm.Show();
}

This opens the second form, but the second form doesn't process
message loops. When the SecondForm closes, I receive a
System.ObjectDisposedException on the line immediately after the
'mySecondForm.Show();' line.
Can anybody suggest what I'm doing wrong?

Nov 16 '05 #2
"Ken Kolda" <ke*******@elliemae-nospamplease.com> wrote in message news:<uW**************@TK2MSFTNGP11.phx.gbl>...
You're almost there, but I don't see any code that calls your
SecondForm.run() method. Basically, all you need to do is to execute the
following in your new thread:

Application.Run(new SecondForm());

Just keep in mind that the Application.Run() call won't return until the
form is closed, so don't put any code after it expecting it to execute right
away.

Ken


Thanks for your help, I've got it working now. I'd also made the
mistake of putting all my SecondForm code into the constructor,
meaning that the message loops where never processed.
Nov 16 '05 #3

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

Similar topics

0
by: Kingdom | last post by:
I Need some serious help here. strugling novis with ASP and javascript any help would be greatly appreciated The script below does exactly what I want it to do for each product on the two passes...
3
by: Brian Keating EI9FXB | last post by:
Hello again, I've already placed a few posts on this topic. This time i've a simple application that exhibits my problem, I've placed sample solution 8k on my website should anyone be interested...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
2
by: superseed | last post by:
Hi, I'm pretty new to C#, and I'm quite stuck on the following problem. I would like to add to my application a Windows.Form (singleton) on which I could display a message of one of the...
2
by: DaWoE | last post by:
Hi all, I'm fairly new to ASP.NET. What i want to do is creat a online registration form. On the first step is getting the users details and the number of people he wants to register. Based on...
3
by: mccoyn | last post by:
When I have a long process to run I can create a new thread to run it and create a modal dialog on my GUI thread. The modal dialog prevents any messages (like button clicks) from working on my...
4
by: =?Utf-8?B?VG9kZCBKYXNwZXJz?= | last post by:
Hey guys, Is there ANY way to accomplish this: (see below)? Basically, I want to have a loop (a < 3 is just for testing purposes, it will be an underermined amount). In this loop, I want to be...
5
by: dk60 | last post by:
Here is a problem I encountered concerning threads: Here is the code in Form1 button click handler: AddForm addForm = new AddForm(booksDataSet.Titles); Thread addTitleThread=new Thread(new...
0
Plater
by: Plater | last post by:
I have been trying to access a messageloop without opening a form. That is, I want to be able to receive messages from other applications through the message loop without having a form. I've read...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...

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.