Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Replaced Task.Factory.StartNew with Task.Run
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Feb 15, 2018
1 parent a61167a commit 8f41caa
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Data_Manager2/Classes/ConnectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private void onClientDisconneting(XMPPClient client)

private void onClientConnected(XMPPClient client)
{
Task.Factory.StartNew(async () =>
Task.Run(async () =>
{
await client.requestRoosterAsync();
await client.requestBookmarksAsync();
Expand Down Expand Up @@ -381,7 +381,7 @@ private void C_NewChatMessage(XMPPClient client, XMPP_API.Classes.Network.Events
}

// ToDo re-implement show toast message
/*Task.Factory.StartNew(() =>
/*Task.Run(() =>
{
if (!msg.getToasted())
{
Expand Down
2 changes: 1 addition & 1 deletion Data_Manager2/Classes/DBManager/DiscoDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private async void INSTANCE_ClientConnected(ConnectionHandler handler, Data_Mana

private void CLIENT_NewDiscoResponseMessage(XMPPClient client, XMPP_API.Classes.Network.Events.NewDiscoResponseMessageEventArgs args)
{
Task.Factory.StartNew(async () =>
Task.Run(async () =>
{
string from = args.DISCO.getFrom();
// Only store direct server results:
Expand Down
6 changes: 3 additions & 3 deletions Data_Manager2/Classes/DBManager/ImageDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private void contiuneAllDownloads()
List<ImageTable> list = dB.Query<ImageTable>(true, "SELECT * FROM " + DBTableConsts.IMAGE_TABLE + " WHERE state = 0 OR state = 1;");
foreach (ImageTable img in list)
{
Task.Factory.StartNew(async () =>
Task.Run(async () =>
{
// Reset image progress:
img.progress = 0;
Expand Down Expand Up @@ -205,7 +205,7 @@ public ImageTable retryImageDownload(ChatMessageTable msg)
img.path = null;
}

Task.Factory.StartNew(async () =>
Task.Run(async () =>
{
update(img);
await downloadImageAsync(img, msg.message);
Expand Down Expand Up @@ -238,7 +238,7 @@ public void downloadImage(ChatMessageTable msg)
{
if (msg.isImage)
{
Task.Factory.StartNew(async () =>
Task.Run(async () =>
{
ImageTable img = new ImageTable()
{
Expand Down
2 changes: 1 addition & 1 deletion Data_Manager2/Classes/MUCHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Task updateBookmarks(XMPPClient client, ConferenceItem cI)
#region --Misc Methods (Private)--
private void enterAllMUCs(XMPPClient client)
{
Task.Factory.StartNew(async () => {
Task.Run(async () => {
foreach (ChatTable muc in ChatDBManager.INSTANCE.getAllMUCs(client.getXMPPAccount().getIdAndDomain()))
{
MUCChatInfoTable info = MUCDBManager.INSTANCE.getMUCInfo(muc.id);
Expand Down
2 changes: 1 addition & 1 deletion Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public static async Task exportLogs()
{
return;
}
await Task.Factory.StartNew(async () =>
await Task.Run(async () =>
{
try
{
Expand Down
2 changes: 1 addition & 1 deletion Push_App_Server/Classes/PushManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static void init()
#region --Events--
private static void INSTANCE_ClientConnected(ConnectionHandler handler, Data_Manager.Classes.Events.ClientConnectedEventArgs args)
{
Task.Factory.StartNew(async () =>
Task.Run(async () =>
{
DataWriter dW = new DataWriter(args.CLIENT);
await dW.connectAndSendAsync();
Expand Down
2 changes: 1 addition & 1 deletion UWP XMPP Client/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void OnSuspending(object sender, SuspendingEventArgs e)
/// </summary>
private void initAllDBManagers()
{
Task.Factory.StartNew(() =>
Task.Run(() =>
{
AccountDBManager.INSTANCE.initManager();
ChatDBManager.INSTANCE.initManager();
Expand Down
2 changes: 1 addition & 1 deletion UWP XMPP Client/Classes/BackgroundImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static void loadCache()
return;
}

Task.WaitAny(Task.Factory.StartNew(async () =>
Task.WaitAny(Task.Run(async () =>
{
Logger.Info("Started loading background images...");
DateTime timeStart = DateTime.Now;
Expand Down
2 changes: 1 addition & 1 deletion UWP XMPP Client/Controls/AccountControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void disableAccount_tggls_Toggled(object sender, RoutedEventArgs e)
{
Account.disabled = !disableAccount_tggls.IsOn;
XMPPAccount newAccount = Account.clone();
Task.Factory.StartNew(() => AccountDBManager.INSTANCE.setAccountDisabled(newAccount, newAccount.disabled));
Task.Run(() => AccountDBManager.INSTANCE.setAccountDisabled(newAccount, newAccount.disabled));
}
}

Expand Down
4 changes: 2 additions & 2 deletions UWP XMPP Client/Controls/ChatDetailsControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ private void showMessages()
chatMessages.AddRange(msgs);

ChatTable cpy = Chat.clone();
Task.Factory.StartNew(() => ChatDBManager.INSTANCE.markAllMessagesAsRead(cpy));
Task.Run(() => ChatDBManager.INSTANCE.markAllMessagesAsRead(cpy));
}
}

Expand Down Expand Up @@ -344,7 +344,7 @@ await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
if (Chat != null && Equals(args.MESSAGE.chatId, Chat.id))
{
Task.Factory.StartNew(async () =>
Task.Run(async () =>
{
for (int i = 0; i < chatMessages.Count; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion UWP XMPP Client/Controls/ChatMasterControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ private void autoEnter_tmfo_Click(object sender, RoutedEventArgs e)
if (MUCInfo != null && MUCInfo.autoEnterRoom != autoEnter_tmfo.IsChecked)
{
MUCInfo.autoEnterRoom = autoEnter_tmfo.IsChecked;
Task.Factory.StartNew(() => MUCDBManager.INSTANCE.setMUCChatInfo(MUCInfo, false, false));
Task.Run(() => MUCDBManager.INSTANCE.setMUCChatInfo(MUCInfo, false, false));

if (Chat.inRoster)
{
Expand Down
4 changes: 2 additions & 2 deletions UWP XMPP Client/Controls/ServerFeaturesControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private void sendDiscoInfo()
{
discoInfosId = "";
Task<string> t = Client.createDiscoAsync(Chat.chatJabberId, DiscoType.INFO);
Task.Factory.StartNew(async () => discoInfosId = await t);
Task.Run(async () => discoInfosId = await t);
startTimerInfos();
}
}
Expand All @@ -138,7 +138,7 @@ private void sendDiscoItems()
{
discoItemsId = "";
Task<string> t = Client.createDiscoAsync(Chat.chatJabberId, DiscoType.ITEMS);
Task.Factory.StartNew(async () => discoItemsId = await t);
Task.Run(async () => discoItemsId = await t);
startTimerItems();
}
}
Expand Down
2 changes: 1 addition & 1 deletion UWP XMPP Client/Dialogs/ClearCacheDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void clearCache()
bool mucMembers = (bool)mucMembers_chbx.IsChecked;
bool reconnect = (bool)reconnect_chbx.IsChecked;

Task.Factory.StartNew(async () =>
Task.Run(async () =>
{
// General:
if (chatMessages)
Expand Down
6 changes: 3 additions & 3 deletions UWP XMPP Client/Pages/ChatPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void loadChats(string selectedChatId)
allChats.Clear();

// Load all chats:
Task.Factory.StartNew(() =>
Task.Run(() =>
{
ChatTemplate selectedChat = null;

Expand Down Expand Up @@ -248,7 +248,7 @@ private void ChatPage2_BackRequested(object sender, BackRequestedEventArgs e)

private void INSTANCE_ChatChanged(ChatDBManager handler, Data_Manager.Classes.Events.ChatChangedEventArgs args)
{
Task.Factory.StartNew(() =>
Task.Run(() =>
{
// Find chat in chatsList:
foreach (ChatTemplate chatTemplate in allChats.Where((x) => x.chat != null && Equals(x.chat.id, args.CHAT.id)))
Expand Down Expand Up @@ -295,7 +295,7 @@ private void INSTANCE_ChatChanged(ChatDBManager handler, Data_Manager.Classes.Ev

private void INSTANCE_MUCInfoChanged(MUCDBManager handler, Data_Manager.Classes.Events.MUCInfoChangedEventArgs args)
{
Task.Factory.StartNew(() =>
Task.Run(() =>
{
foreach (ChatTemplate chatTemplate in allChats.Where((x) => x.chat != null && x.chat.chatType == ChatType.MUC && Equals(x.chat.id, args.MUC_INFO.chatId)))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public AccountSettingsPage()
#region --Misc Methods (Private)--
private void loadAccounts()
{
Task.Factory.StartNew(() =>
Task.Run(() =>
{
IList<XMPPAccount> list = AccountDBManager.INSTANCE.loadAllAccounts();

Expand Down
4 changes: 2 additions & 2 deletions UWP XMPP Client/Pages/SettingsPages/MiscSettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public MiscSettingsPage()
private void showImageChacheSize()
{
imageChacheSize_tblck.Text = "calculating...";
Task.Factory.StartNew(async () => {
Task.Run(async () => {
long size = await ImageDBManager.INSTANCE.getCachedImagesFolderSizeAsync();
string text = "~ ";
if (size >= 1024)
Expand All @@ -74,7 +74,7 @@ private void showImageChacheSize()
private void showLogSize()
{
logSize_tblck.Text = "calculating...";
Task.Factory.StartNew(async () => {
Task.Run(async () => {
long size = await Logger.getLogFolderSizeAsync();
string text = "~ ";
if (size >= 1024)
Expand Down
2 changes: 1 addition & 1 deletion XMPP_API/Classes/Network/TCP/TCPConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public void startReaderTask()
throw new InvalidOperationException("[TCPConnection]: Unable to start reader task! ConnectionState != Connected! state = " + state);
}

Task.Factory.StartNew(() =>
Task.Run(() =>
{
string data = null;
int errorCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion XMPP_API/Classes/Network/XMPPConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ private async Task reconnectAsync()
/// <param name="delayed">If the message got send delayed (e.g. stored in message cache).</param>
private void onMessageSend(string id, bool delayed)
{
Task.Factory.StartNew(() => MessageSend?.Invoke(this, new MessageSendEventArgs(id, delayed)));
Task.Run(() => MessageSend?.Invoke(this, new MessageSendEventArgs(id, delayed)));
}

#endregion
Expand Down

0 comments on commit 8f41caa

Please sign in to comment.