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.Sh ow();
}
This opens the second form, but the second form doesn't process
message loops. When the SecondForm closes, I receive a
System.ObjectDi sposedException on the line immediately after the
'mySecondForm.S how();' line.
Can anybody suggest what I'm doing wrong? 2 5037
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*********@gm ail.com> wrote in message
news:91******** *************** **@posting.goog le.com... 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.Sh ow(); }
This opens the second form, but the second form doesn't process message loops. When the SecondForm closes, I receive a System.ObjectDi sposedException on the line immediately after the 'mySecondForm.S how();' line.
Can anybody suggest what I'm doing wrong?
"Ken Kolda" <ke*******@elli emae-nospamplease.co m> wrote in message news:<uW******* *******@TK2MSFT NGP11.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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 it makes however I would like the entire script to loop 34
times and on each of those 30 loops also write the product and the price
(only) onto the...
|
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 in
having a look. http://briankeating.net/transfer/test.zip
To recap the problem I expected (and found).
I've a main GUI thead (main form), this...
|
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 quite a few
words in this post but the questions are actually quite similar and
should be fairly quick to answer ...
(1) What is Happening with...
|
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 following type :
Exception, Error, Warning, Infos (with differents colors, etc).
I would like to use it like the Console.WriteLine("My Message"); on...
|
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 the number of people i want to create a form where he can enter
the persons details.
For example he wants to register 3 people. Then the second...
| |
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 main Form. It also provides
a message loop, which allows paint messages and calls to the Control::Invoke
function to run. I can use these to...
|
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 able to create a new cell each time. In
this cell, I want the variable name to change. Is this at ALL possible? I've
never been able to figure this...
|
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
ThreadStart(addForm.GetNewTitle));
addTitleThread.Start();
Here is the code in AddForm:
|
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 that you can use Application.Run() without an argument to create a loop without a form, but I have no way of sending messages to that loop (that i...
|
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...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |