25.04.2015, 16:31
(
Последний раз редактировалось ikkentim; 25.04.2015 в 21:30.
)
Quote:
Is this thread-safe? Can I use async-await without worry?
Are there any drawbacks using this instead of pawn? |
I have however made a Sync function:
PHP код:
Sync.Sync.Run(() => {
// do something on main thread
});
// - or -
var result = await Sync.RunAsync(() => {
// do calls to native functions on the main thread and return the value...
return 0;
});
// I know the method names of of Sync.Run and Sync.RunAsync are dodgy. They should be named the other way around. Will change this soon.
https://github.com/ikkentim/SampShar...s/ASyncTest.cs
I advise only to use multi-threading for awaiting database access (and syncing directly afterwards) and for heavy calculations.
The only drawbacks I can think of is that most if not all scripts and plugins on these forums are made for use with pawn. Although most includes are easily converted, and the streamer plugin I've already written a wrapper for, you cannot simply copy and paste much from these forums without some thinking.
EDIT: side note: the console functions internally check whether it's called on the main thread. If not, it will automatically sync. This means you can use the console functions even from different threads.