Thursday, 15 April 2010

c# - Background Worker loading screen in Winforms -


I have a form where anyone can sign in and it may take some time until the data is loaded into the form is. So when I wanted to create a different form (Lodskrinkas) with a progress bar on the form load times I tried it in Lodskrin. Cs form:

  private void form L_lod (object sender , EventArgs e) {worker = New BackgroundWorker (); Worker.workerReportsProgress = true; Worker Cancel worker support = true; Worker.DoWork + = New DoWorkEventHandler (worker_DoWork); modus operandi. Changed progress + = new progress has changed EventHandler (work_progressChanged); Worker.RunWorkerCompleted + = Includes new RunWorkerAventHandler (work_workwork complete); } Zero worker_dowork (object sender, doWorkEventArgs e) {int percentFinished = (int) e.Argument; While (! Worker! Cancellation amp; amp; percent ended; 100 & lt; 100) Worker.ReportProgress (percentFinished); System.Threading.Thread.Sleep (50); } E.Result = percentFinished; } Zero WorkerGridger changed (Object Sender, Progress Changed and Evergius E) {progressBar1.Value = E. Progress percentage; } Zero worker_RunWorker complete (object sender, runwalker, computing, and e-mails) {this.Close (); }  

I have read that the worker_DoWork method should contain the code that takes longer to load. I do not know why my button is in Form 1. When it is clicked, I go to the next class with

  private void SignIn_Click (object sender, EventArgs e) {var Login = new Login (it); LogIn.checkUserInput (this); }  

And there I carry out some things to load. How to connect everything? I need help!

I'm really in the process of creating a general purpose dialog for this kind of thing, for you will not be ready in time for use, but I would suggest that you go with the similar lines to create your "load" dialog so that he would accept a representative and DoWork event handler Invites the method in the main form that can be included Which works and you can pass a representative to that method for communication. I will post a very basic example

  Public Partial Sections Form 1: Form {Public Form 1 () {InitializeComponent (); } Private Datatable Table; Private Zero Button 1_Click (Object Sender, EventsErgus E) {var work = new Action (GetData); (Var f2 = new form 2 (work)) {f2.ShowDialog (); This.dataGridView1.DataSource = this.table; }} Private Zero GetData () {this.table = New DataTable (); (Var adapter = Select new Skyueldataadaptr ( "My Tayl", "connection string here using")) (adapter.Fill (table);}}} public partial class Form 2: Form {private action work; public form 2 (action work) {InitializeComponent (); This.work = work;} private void form 2_lod (object sender, Iventarges e) {ThiskbackgroundWorkerlkRunWorkerAsync ();} private void Prishtbhumivrkr L_DoWork (object sender, DoWorkEventArgs e) {This.work ();} Private Zero Background Worker 1_River Spuarn (object sender, Rnvokr Completed Aventarges e) {this.DialogResult = DialogResult.OK;}}  

Note that the measure of progress using data adapter is no real way , So you can display only one marquee progress bar in this case.


No comments:

Post a Comment