run async methods within a sync process
C#
public static class AsyncUtil
{
private static readonly TaskFactory TaskFactory = new
TaskFactory(CancellationToken.None,
TaskCreationOptions.None,
TaskContinuationOptions.None,
TaskScheduler.Default);
/// <summary>
/// Executes an async Task method which has a void return value synchronously
/// USAGE: AsyncUtil.RunSync(() => AsyncMethod());
/// </summary>
/// <param name="task">Task method to execute</param>
public static void RunSync(Func<Task> task)
=> TaskFactory
.StartNew(task)
.Unwrap()
.GetAwaiter()
.GetResult();
/// <summary>
/// Executes an async Task<T> method which has a T return type synchronously
/// USAGE: T result = AsyncUtil.RunSync(() => AsyncMethod<T>());
/// </summary>
/// <typeparam name="TResult">Return Type</typeparam>
/// <param name="task">Task<T> method to execute</param>
/// <returns></returns>
public static TResult RunSync<TResult>(Func<Task<TResult>> task)
=> TaskFactory
.StartNew(task)
.Unwrap()
.GetAwaiter()
.GetResult();
}
Also in C#:
- Title
- c# to vb.net
- Category
- C#
- Title
- c# how to initialize an array
- Category
- C#
- Title
- order by C#
- Category
- C#
- Title
- how to generate random unique id in c#
- Category
- C#
- Title
- c# inline if
- Category
- C#
- Title
- c# making a folder wpf
- Category
- C#
- Title
- unity instantiate an object
- Category
- C#
- Title
- unity transformer double en float
- Category
- C#
- Title
- date time heutiges datum
- Category
- C#
- Title
- validating file upload asp.net core mvc
- Category
- C#
- Title
- find negative version of integer in c#
- Category
- C#
- Title
- how to convert int to string unity c#
- Category
- C#
- Title
- remove all array elements c#
- Category
- C#
- Title
- uinput dialog uwp c#
- Category
- C#
- Title
- iframe set html content c#
- Category
- C#
- Title
- c# check internet connection easy
- Category
- C#
- Title
- countdown script unity
- Category
- C#
- Title
- how to record number of times using application in c#
- Category
- C#
- Title
- blazor display validation message
- Category
- C#
- Title
- c# number suffixes
- Category
- C#
- Title
- c sharp exit while loop
- Category
- C#
- Title
- add new page to site c# programmatically
- Category
- C#
- Title
- Failed to retrieve Firebase Instance Id
- Category
- C#
- Title
- how to locate a specific element in a list c#
- Category
- C#
- Title
- open zip file in c#
- Category
- C#
- Title
- add variable to the beginning of a list c#
- Category
- C#
- Title
- c# quaternion eular calculator
- Category
- C#
- Title
- c# iorderedenumerable to dictionary
- Category
- C#
- Title
- How to get the world position of the edge of an object?
- Category
- C#
- Title
- c# mathf.ceiling
- Category
- C#
- Title
- isdaylightsavingtime in c#
- Category
- C#
- Title
- unity list length
- Category
- C#
- Title
- nunit return parameter
- Category
- C#
- Title
- unity serializefield
- Category
- C#
- Title
- asp.net list all files in folder
- Category
- C#
- Title
- c# clear list items
- Category
- C#
- Title
- never lose focus textbox c#
- Category
- C#
- Title
- error CS0542
- Category
- C#
- Title
- c# how to refreshyour bindingsource
- Category
- C#
- Title
- Check object is in layermask unity
- Category
- C#
- Title
- wpf get name of clicked element
- Category
- C#
- Title
- C# invoke
- Category
- C#
- Title
- how to check if a value is inside an array c#
- Category
- C#
- Title
- non null array length
- Category
- C#
- Title
- c# image to byte array
- Category
- C#
- Title
- how to exit a program in c#
- Category
- C#
- Title
- how to make a for loop in c#
- Category
- C#
- Title
- calculate impact damage + unity
- Category
- C#
- Title
- unity 2d Drag object
- Category
- C#
- Title
- c# round number up
- Category
- C#
- Title
- asp list box
- Category
- C#
- Title
- xamarin hide back button
- Category
- C#
- Title
- unity button interactable
- Category
- C#
- Title
- linq in c#
- Category
- C#
- Title
- c list add element
- Category
- C#
- Title
- movement script c#
- Category
- C#
- Title
- public enum c#
- Category
- C#
- Title
- c# md5 int
- Category
- C#
- Title
- degree between two points latitude longitude c#
- Category
- C#
- Title
- unity custom editor save changes
- Category
- C#
- Title
- how to get length of okobjectresult c#
- Category
- C#
- Title
- creating a c# class
- Category
- C#
- Title
- hwo to make an array in C#
- Category
- C#
- Title
- exit game unity
- Category
- C#
- Title
- unity making homing missile
- Category
- C#
- Title
- how to route back to url using Request.Headers["Referer"].ToString() in asp.net core
- Category
- C#
- Title
- if statement conditions c#
- Category
- C#
- Title
- how to get array of children transform
- Category
- C#
- Title
- IEnumerator
- Category
- C#
- Title
- how to create and trigger a function unity animation events
- Category
- C#
- Title
- c# arraylist contains
- Category
- C#
- Title
- constructor in inherited class c#
- Category
- C#
- Title
- unity oncollisionenter2d
- Category
- C#
- Title
- How to set an expiry date on a program
- Category
- C#
- Title
- c# find duplicates in list
- Category
- C#
- Title
- get first and last item list c#
- Category
- C#
- Title
- c# polymorphism
- Category
- C#
- Title
- how to stop player rotating when hit by object
- Category
- C#
- Title
- multidimensional meaning
- Category
- C#
- Title
- freeze position unity c#
- Category
- C#
- Title
- how to delay something in c# unity
- Category
- C#
- Title
- fahrenheit to celsius c#
- Category
- C#
- Title
- unity how to get transform scale
- Category
- C#
- Title
- c# scene manager
- Category
- C#
- Title
- c# create new thread
- Category
- C#
- Title
- c# get pc ip address
- Category
- C#
- Title
- c# int
- Category
- C#
- Title
- c# how to compare 2 dates without time
- Category
- C#
- Title
- Celsius to Fahrenheit c#
- Category
- C#
- Title
- set int to null c#
- Category
- C#
- Title
- c# AllowSynchronousIO to true
- Category
- C#
- Title
- transform object according to its parent unity
- Category
- C#
- Title
- how to reference function in unity
- Category
- C#
- Title
- linq query select top 1 c#
- Category
- C#
- Title
- sending data photon c#
- Category
- C#
- Title
- how to access first child of parent unity
- Category
- C#
- Title
- how to populate listbox using list<t> c#
- Category
- C#
- Title
- lazy loading c#
- Category
- C#
- Title
- unity set position
- Category
- C#
- Title
- unity round
- Category
- C#