首页 > 代码库 > C# framework 4.0 使用UI线程--Task

C# framework 4.0 使用UI线程--Task

 

using System.Threading.Tasks;

//保存污染因子
private void btSavePF_Click(object sender, EventArgs e)
{
try
{
Task task = Task.Factory.StartNew(() =>
{
SavaPollutionFactor(); // 耗时运算
});
Task UITask = task.ContinueWith(t =>
{
btSavePF.Enabled = true;
picLoading.Visible = false;
}, TaskScheduler.FromCurrentSynchronizationContext());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


}

//保存因子具体方法
private void SavaPollutionFactor()
{
try
{


}
catch (Exception ex)
{

}

}

C# framework 4.0 使用UI线程--Task