当我将 .net目标从框架4.5更改为框架4.0 时。
我在一行RUN
>>>中收到错误System.Threading.Tasks.Task.Run(() => {
PrintFactory.sendTextToLPT1(strPrint);
});
这可能是什么原因??
我的代码段:
private void button4_Click(object sender, EventArgs e)
{
//string filePath = image_print();
// MessageBox.Show(filePath, "path");
string newFilePath = image_print();
string strText = string.Empty;
using (StreamReader stream = new StreamReader(newFilePath))
{
strText = stream.ReadToEnd();
stream.Close();
}
string strPrint = strText + Print_image();
if (String.IsNullOrEmpty(strPrint) || String.IsNullOrEmpty(img_path.Text))
{
return;
}
else
{
sendfile.Image splash = new sendfile.Image();
this.Hide();
splash.Show();
System.Threading.Tasks.Task.Run(() => {
PrintFactory.sendTextToLPT1(strPrint);
}); //<<< here i am getting error in RUN
splash.FormClosed += delegate {
System.IO.File.Delete(newFilePath);
this.Show();
};
}
}
答案 0 :(得分:1)
System.Threading.Tasks.Task.Run
。您需要使用Task.Factory.StartNew
:
System.Threading.Tasks.Task.Factory.StartNew(() => {
PrintFactory.sendTextToLPT1(strPrint);
});