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

background worker and win forms

I need help with background worker and form

I have a class (form1) that works with database. I need this:
-Show form2 while form1 is geting data from database
-When form1 is done, close form2, proced working form1

I try these things with thread but a can not do it
I try it with background worker, but I
dont know how:(

does enyone knows how to do this thing.

Thanx in advance

Oga

May 31 '06 #1
1 1766
Hi Oga,

It sounds like the piece you are missing is something like this....

When the Background Thread (the database work) in 'form1' is done, you
will need to fire an event. First, create a delegate to handle the
closing of 'form2' by a Background Thread, and the Event that will be
fired:

public delegate void Form1DoneDelegate();
public event Form1DoneDelegate WorkFinishedEvent;

Then, subscribe to that Event in 'form1':

Form1.WorkFinishedEvent+= new Form1DoneDelegate (CloseForm2);
Finally, create the 'CloseForm2' method (it needs to close 'form2', or
whatever) - something like this:

private void CloseForm2()
{
if (Form2.InvokeRequired) //Make sure we are on the main UI
thread
{
BeginInvoke(new Form1DoneDelegate(CloseForm2));
}
else
{
Form2.Close();
}
}

Note that the number of arguments for the delegate (Form1DoneDelegate)
and method (CloseForm2) match - they are zero. You can add some if you
need to.
Hope this helps.
Dave
bi*****@gmail.com wrote:
I need help with background worker and form

I have a class (form1) that works with database. I need this:
-Show form2 while form1 is geting data from database
-When form1 is done, close form2, proced working form1

I try these things with thread but a can not do it
I try it with background worker, but I
dont know how:(

does enyone knows how to do this thing.

Thanx in advance

Oga


May 31 '06 #2

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

Similar topics

10
by: Cool Guy | last post by:
Consider: void Start() { if (!TryToDoSomething()) ShowErrorMessage(); }
7
by: Jeff Stewart | last post by:
I need a thread to run a subroutine which updates my main form's progress bar. I've properly marshaled all UI updates to the main UI thread, and after the main thread starts the worker thread, it...
7
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works...
6
by: sjoshi | last post by:
I'm able to use the Bacground Worker class to execute task and pain the UI. However I want to be able to execute n tasks in order, say n1, then n2 if there were no errors during n1, n3 so on. ...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
4
by: Jesse Aufiero | last post by:
I'm wondering what the rule is on how to assure that the background worker 'DoWork' routine is truly running entirely in the background. My DoWork routine calls another procedure which resides in...
4
by: csharpula csharp | last post by:
Hello, Can you please tell me if I should use the background worker in the following way: if (worker.IsBusy) worker.CancelAsync(); (or I can avoid this if)? And in case I want to restart the...
7
by: csharpula csharp | last post by:
Hello, I got a question regarding the usage of background worker. How can I run few threads via background worker with different objects as parameter each time. I understood that I can't do...
1
by: Infog | last post by:
I am trying to code a simple background workers class without needing to use the backgroundworker object on a form. This would allow me to use a background worker in any class without writing much...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.