public string GetAsync(string url, bool noCache = false, Dictionary <string, object> headers = null) { string result = null; var thread = ScriptService.CurrentThread; Task.Run(() => Get(url, noCache, headers)) .ContinueWith(t => { result = t.Result.ReadString(); ScriptService.ResumeThread(thread); }); ScriptService.YieldThread(); return(result); }
public string PostAsync(string url, string data, string contentType = "application/json", bool compress = false, Dictionary <string, object> headers = null) { string result = null; var thread = ScriptService.CurrentThread; Task.Run(() => Post(url, data, contentType, compress, headers)) .ContinueWith(t => { result = t.Result; ScriptService.ResumeThread(thread); }); ScriptService.YieldThread(); return(result); }
public void PreloadAsync(LuaTable contentUrls) { var thread = ScriptService.CurrentThread; ScriptService.YieldThread(); var count = contentUrls.Length; var tasks = new Task[count]; for (int i = 0; i < count; i++) { var contentUrl = (string)contentUrls[count]; tasks[i] = DownloadStream(contentUrl).ContinueWith(t => Cache(contentUrl, t)); } Task.WhenAll(tasks).ContinueWith(t => ScriptService.ResumeThread(thread)); }
private LuaTable GetDevices(DataFlow dataFlow) { var table = new LuaTable(); var thread = ScriptService.CurrentThread; int i = 0; Task.Run(() => { using (var enumerator = new MMDeviceEnumerator()) foreach (var device in enumerator.EnumAudioEndpoints(dataFlow, DeviceState.Active)) { table[i++] = device.FriendlyName; } }).ContinueWith(x => ScriptService.ResumeThread(thread)); ScriptService.YieldThread(); return(table); }
public LuaTable GetClanInfoAsync(uint clanId) { var thread = ScriptService.CurrentThread; var table = new LuaTable(); Task.Run(() => { var steamId = SteamIdFromClanId(clanId); var owner = SteamFriends.GetClanOwner(steamId); table["Name"] = SteamFriends.GetClanName(steamId); table["Owner"] = new LuaTable { ["Name"] = SteamFriends.GetFriendPersonaName(owner), ["Id"] = owner.GetAccountID().m_AccountID }; table["Tag"] = SteamFriends.GetClanTag(steamId); table["Roles"] = new LuaTable { [1] = new LuaTable { [Name] = "Officer", } [2] = new LuaTable { [Name] = "Moderator" } [3] = new LuaTable { [Name] = "Member" } }; }).ContinueWith(x => ScriptService.ResumeThread(thread)); ScriptService.YieldThread(); return(table); }