Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Ok here's the pretty light code:

// 
// numConfigsBindingSource
// 
this.numConfigsBindingSource.DataMember = "NumConfigs";
this.numConfigsBindingSource.DataSource = this.DSNumConfigs;

// Grid
this.GridNumConfigs.DataSource = this.numConfigsBindingSource;

// 
// DSNumConfigs
// 
this.DSNumConfigs.DataSetName = "DSNumConfigs";
this.DSNumConfigs.SchemaSerializationMode = System.Data.SchemaSerializationMode.IncludeSchema;
// 
// numConfigsTableAdapter
// 
this.numConfigsTableAdapter.ClearBeforeFill = false;
//
// 
// DSConfigNumbers
// 
this.DSConfigNumbers.DataSetName = "DSConfigNumbers";
this.DSConfigNumbers.EnforceConstraints = false;
this.DSConfigNumbers.SchemaSerializationMode =       System.Data.SchemaSerializationMode.IncludeSchema;

private void Form1_Load(object sender, EventArgs e)
{                
    worker.RunWorkerAsync();
}

private void worker_DoWork(object sender, DoWorkEventArgs e)
{
    this.numConfigsTableAdapter.Fill(this.DSNumConfigs.NumConfigs);                    
}

Then I run this code under VS2010 it works find but when I just run release application it's hanging. But if I rewrite this code that isn't using BackgroundWorkers it's works fine. Do I need some effort to clearly release background worker? I have tried to lock worker class in Form1_Load it isn't provide any success. Also have tried to lock this.DSNumConfigs in DoWork and also no any successful stuff.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
226 views
Welcome To Ask or Share your Answers For Others

1 Answer

Well, you're doing something unsafe: you're accessing the UI on a non-UI thread. You're not doing so explicitly, but your UI is bound to your table adapter.

You may want to unbind, then run the background worker, then (on the completed event) rebind the UI.

I'm surprised that it's not throwing an exception when you run it in the debugger, to be honest...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...