user4240000
user4240000

Reputation:

Getting error called constructor has been deprecated

When i changed my .net target from framework 4.5 to framework 4.0. i am getting an error in one line RUN>>> System.Threading.Tasks.Task.Run(() => { PrintFactory.sendTextToLPT1(strPrint); });

What could be the reason for this??

My code snippet:

 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();
            };
        }
    }

Upvotes: 0

Views: 135

Answers (1)

Christoph Fink
Christoph Fink

Reputation: 23113

System.Threading.Tasks.Task.Run does not exist in .NET 4.0. You need to use Task.Factory.StartNew:

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

Upvotes: 1

Related Questions