|
асинхронный вызов своей функции
|
|||
---|---|---|---|
#18+
туплю, не могу понять public static async void AsyncIntroParallel() { await KP(); } private static async Task<bool> KP() { bool fl = false; ........ циклы и тп ........ return fl;} ругается Warning 2: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. и функция KP выполняется в синхронном режиме. В функции чистые расчеты и никаких асинхронных вызовов нет. что я делаю не так? ... |
|||
:
Нравится:
Не нравится:
|
|||
17.09.2012, 01:41 |
|
асинхронный вызов своей функции
|
|||
---|---|---|---|
#18+
забыл упомянуть что в процедуре KP идет вызов синхронной тяжелой процедуры, может это как то не дает основной процедуре перейти в асинхронный режим? private static async Task<bool> KP() { bool fl = false; for (int x = 5; x < 1000; x++) for (int y = 5; y < 1000; y++) { MyLondCalculation(Matrix, true); } return fl; } calling of procedure: ...... KP(); ...... ... |
|||
:
Нравится:
Не нравится:
|
|||
17.09.2012, 11:48 |
|
асинхронный вызов своей функции
|
|||
---|---|---|---|
#18+
разобрался с асинхронностью public async void MyAsyncStep1() { bool result = await KrisitnaPlay(); if (result) { WhoTurn.Text = "ok"; } else { } } private Task<bool> MyAsyncStart() { return Task.Run(() => { bool flag = true; MyAsyncStep1(); return flag; }); } вызов .... MyAsyncStart(); запускается все работает асинхронно WhoTurn.Text = "ok"; но на этой ноге спотыкается с ошибкой An exception of type 'System.Exception' occurred in TicTacToeProfessional.exe but was not handled in user code Additional information: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)) ... |
|||
:
Нравится:
Не нравится:
|
|||
17.09.2012, 13:45 |
|
|
start [/forum/topic.php?fid=21&fpage=37&tid=1441668]: |
0ms |
get settings: |
9ms |
get forum list: |
13ms |
check forum access: |
4ms |
check topic access: |
4ms |
track hit: |
45ms |
get topic data: |
11ms |
get forum data: |
2ms |
get page messages: |
42ms |
get tp. blocked users: |
2ms |
others: | 331ms |
total: | 463ms |
0 / 0 |