获取错误称为构造函数已被弃用

时间:2014-11-11 14:34:34

标签: c# wpf

当我将 .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();
            };
        }
    }

1 个答案:

答案 0 :(得分:1)

.NET 4.0中不存在

System.Threading.Tasks.Task.Run。您需要使用Task.Factory.StartNew

System.Threading.Tasks.Task.Factory.StartNew(() => {
    PrintFactory.sendTextToLPT1(strPrint);
});