c# - Task Scheduling seems different when debugger is attached -


we have wpf software makes use quite lot of “async await” pattern in order not block ui thread.

for instance, use pattern when opening file: ui shows spinner while in background io loading operation , start tasks long calculations (which should not stop loading)

what seems happen loading task launched on thread, not blocking ui. works. however, loading task seems run synchronously other tasks create, such long calculation loading not need.

i pinpoint debugger because:

  • i noticed big files, when debugger attached, spinner runs longer 10-20 times.
  • running release or debug version not affect behavior.
  • as long debugger attached, way slower.
  • detaching debugger in middle of loading run super fast right afterwards.

i know because when breaking debugger, see:

  • on current thread, top of call stack “loadprojectasync”,
  • that thread in code of long calculations, have been triggered “async void” (since don't care them , shouldn't run synchronously)
  • the “tasks” window in visual studio show 1 "active" task, , other tasks in “complete” status. never saw 2 tasks active in session.

here’s little code layout (this simplified version give idea of flow) clicking on button, ui calls loadprojectfile method, looks following:

public async void loadprojectfile(string path) {     showspinner = true;      var projectfilemodel = await projectmanager.loadprojectasync(path)      //… more stuff here. work fine , shouldn't related problem      showspinner = false; }  public class projectmanager {     public task<projectmodel> loadprojectasync(string filepath)     {         return task.run(() => loadproject(filepath));     }      public projectmodel loadproject(string filepath)     {         //opens file                           var model = new projectmodel(filepath);          dosomecomputations(model);          return model;     }      public async void dosomecomputations()     {                     //computations made here using "await".         //they seem run synchronously ,          //block loadproject function,          //which not require @ these results.         await task.delay(1000).configureawait(false);     } } 

sadly, if make project simplified code, runs debugger attached , not show symptoms i'm describing.

i understand new task not mean new thread, shouldn't reason why in case.

i understand why scheduling different (or whatever else happening) , it?


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -