PDA

View Full Version : حرفه ای: قفل کردن برنامه هنگام استفاده از بک گراند ورکر و ترد



hamid_73
دوشنبه 18 اسفند 1393, 21:14 عصر
با سلام
دوستان من می خوام اطلاعات همه ردیف های جدول پایگاه داده ام رو ویرایش کنم ولی موقعی که اینکارو می کنم برنامه قفل می کنه و نمیذاره هیچ کاری بکنم
با اینکه از bgworker و thread استفاده کردم باز هم برنامه قفل میکنه موقع ویرایش سطر های جدول هم بالای 100 تا هست
من هرچی جستجو کردم به هیچ نتیجه ای نرسیدم واقعا مشکل بزرگی هست برام من اینجوری کارم رو انجام می دم ولی باز هم قفل می کنه.

public Form1()
{
InitializeComponent();
bgworker = new BackgroundWorker();

// Create a background worker thread that ReportsProgress &
// SupportsCancellation
// Hook up the appropriate events.
bgworker.DoWork += new DoWorkEventHandler(bgworker_DoWork);
bgworker.ProgressChanged += new ProgressChangedEventHandler
(bgworker_ProgressChanged);
bgworker.RunWorkerCompleted += new RunWorkerCompletedEventHandler
(bgworker_RunWorkerCompleted);
bgworker.WorkerReportsProgress = true;
bgworker.WorkerSupportsCancellation = true;
}


private void bgworker_DoWork(object sender, DoWorkEventArgs e)
{
replace_field();
}


void bgworker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// The background process is complete. We need to inspect
// our response to see if an error occurred, a cancel was
// requested or if we completed successfully.
if (e.Cancelled)
{
lblStatus.Text = "عملیات متوقف شد.";
}

// Check to see if an error occurred in the background process.

else if (e.Error != null)
{
lblStatus.Text = "مشکلی در عملیات به وجود آمده است.";
}
else
{
// Everything completed normally.
lblStatus.Text = "عملیات با موقیت انجام شد";
}

//Change the status of the buttons on the UI accordingly
//btnStartAsyncOperation.Enabled = true;
//btnCancel.Enabled = false;
}


void bgworker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{

// This function fires on the UI thread so it's safe to edit

// the UI control directly, no funny business with Control.Invoke :)

// Update the progressBar with the integer supplied to us from the

// ReportProgress() function.

progressBar1.Value = e.ProgressPercentage;
lblStatus.Text = "درحال اعمال تغییرات......" + progressBar1.Value.ToString() + "%";
}

rambod18
سه شنبه 19 اسفند 1393, 08:03 صبح
توی کد thread یا backgroundworker
کد

this.disable =true;

https://social.msdn.microsoft.com/Forums/en-US/4ebd5faf-80ac-4b4f-99bc-f11b4ded1483/c-enable-disable-form?forum=csharplanguage

hamid_73
سه شنبه 19 اسفند 1393, 19:00 عصر
همچین کدی نداره از لینک زیر هم سر در نباوردم