There is a method

private void Generate(int xMax, int yMax, int categoryCount, int elementCount) { elementList = generator.GenerateSample( new Interval(0, xMax), new Interval(0, yMax), categoryCount, elementCount ); ElementsGenerated(); } 

With its usual execution:

 Generate(xMax, yMax, categoryCount, elementCount); 

, the program runs ~ 8,9770973 with

Using:

 await Task.Factory.StartNew(() => Generate(xMax, yMax, categoryCount, elementCount)); 

runtime goes as much as ~ 42,6324051 s

I need exactly the second method, because the progress bar is updated and the information labels on the label are displayed, and in the first case only the progress bar changes are visible, the inscriptions do not change, and the whole window is also inactive.

  • Strange, this should not be. Try to profile the execution: measure with StopWatch each of the pieces in synchronous and asynchronous modes. How do you update the progress bar and label? Provide more code, for example, the relevant part of the procedure calling await . - VladD
  • 2
    Found an interesting feature of your code. The point is that the task I have at the moment is the generation of elements, I generate about 10kk elements, and an event is thrown out at every generated element. Apparently events - this is the main reason for such a long implementation. Slightly changed the structure of the program, making not the element-by-element discarding of events, but a percentage, performing at 20kk elements - 4-5 with - MorkOFF
  • Well, yes, if you have 10M synchronous calls to a UI stream, it will be slow. Switch to asynchronous calls (and of course, 10M is too much). - VladD
  • 2
    @KoVadim: Well, it's not good for business logic to know such UI details as the width of the progress bar in pixels. Conceptually, the right solution would be to expose IObservable , and let the UI code cluster it as it wants. - VladD
  • one
    @KoVadim: And it (business logic) will not pull if VM issues IObservable . The UI will subscribe to it via [ Distinct(value / maxValue * pixelWidth) ] (msdn.microsoft.com/en-us/library/hh211630.aspx), and then the VM does not have to worry about the presence of a UI at all. - VladD

0