1

The following doesn't compile. This is for asynchronous calls in a 4.0, aspx WebForms page.

var task = Task.Factory.StartNew(() => Thread.Sleep(100));
var pat = new PageAsyncTask(task); //Doesn't compile, no such signature.
Page.RegisterAsyncTask(pat);

Google searching is failing me because of all the irrelevant 4.5 material that I can't use. By that I mean, I can't use 4.5.

If I just use a Task without RegisterAsyncTask, I get a warning that bare Tasks are not supported in WebForms, or it hangs.

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164

1 Answers1

1

You are almost there. Instead of constructing PageAsyncTask with a task, construct it with a method that returns the task, like so:

var pat = new PageAsyncTask(() => Task.Run(() => Thread.Sleep(100)));

For .Net 4.0:

Action a = () => Thread.Sleep(100); var p = new PageAsyncTask((s, e, cb, o) => a.BeginInvoke(cb, o), a.EndInvoke, null, null);

otto-null
  • 593
  • 3
  • 15