diff --git a/Examples/EFCoreBot/Program.cs b/Examples/EFCoreBot/Program.cs
index 3d983e1..37f5587 100644
--- a/Examples/EFCoreBot/Program.cs
+++ b/Examples/EFCoreBot/Program.cs
@@ -20,5 +20,5 @@ var bot = BotBaseBuilder.Create()
.DefaultLanguage()
.Build();
-bot.Start();
-await Task.Delay(-1);
\ No newline at end of file
+await bot.Start();
+await Task.Delay(-1);
diff --git a/TelegramBotBase/BotBase.cs b/TelegramBotBase/BotBase.cs
index bac92e3..3ac4f52 100644
--- a/TelegramBotBase/BotBase.cs
+++ b/TelegramBotBase/BotBase.cs
@@ -80,7 +80,7 @@ public class BotBase
///
/// Start your Bot
///
- public void Start()
+ public async Task Start()
{
if (Client == null)
{
@@ -89,16 +89,15 @@ public class BotBase
Client.MessageLoop += Client_MessageLoop;
-
if (StateMachine != null)
{
- Sessions.LoadSessionStates(StateMachine);
+ await Sessions.LoadSessionStates(StateMachine);
}
//Enable auto session saving
if (GetSetting(ESettings.SaveSessionsOnConsoleExit, false))
{
- Console.SetHandler(() => { Sessions.SaveSessionStates(); });
+ Console.SetHandler(() => { Sessions.SaveSessionStates().GetAwaiter().GetResult(); });
}
DeviceSession.MaxNumberOfRetries = GetSetting(ESettings.MaxNumberOfRetries, 5);
@@ -141,7 +140,7 @@ public class BotBase
///
/// Stop your Bot
///
- public void Stop()
+ public async Task Stop()
{
if (Client == null)
{
@@ -149,11 +148,9 @@ public class BotBase
}
Client.MessageLoop -= Client_MessageLoop;
-
-
Client.StopReceiving();
- Sessions.SaveSessionStates();
+ await Sessions.SaveSessionStates();
}
///
@@ -407,4 +404,4 @@ public class BotBase
}
#endregion
-}
\ No newline at end of file
+}
diff --git a/TelegramBotBase/Form/Navigation/NavigationController.cs b/TelegramBotBase/Form/Navigation/NavigationController.cs
index 01931e8..b29e203 100644
--- a/TelegramBotBase/Form/Navigation/NavigationController.cs
+++ b/TelegramBotBase/Form/Navigation/NavigationController.cs
@@ -69,7 +69,7 @@ public class NavigationController : FormBase, IStateForm
}
- public void LoadState(LoadStateEventArgs e)
+ public async Task LoadState(LoadStateEventArgs e)
{
if (e.Get("$controller.history.count") == null)
{
@@ -144,13 +144,13 @@ public class NavigationController : FormBase, IStateForm
form.Client = Client;
form.NavigationController = this;
- form.OnInit(new InitEventArgs());
+ await form.OnInit(new InitEventArgs());
History.Add(form);
}
}
- public void SaveState(SaveStateEventArgs e)
+ public Task SaveState(SaveStateEventArgs e)
{
e.Set("$controller.history.count", History.Count.ToString());
@@ -175,6 +175,8 @@ public class NavigationController : FormBase, IStateForm
i++;
}
+
+ return Task.CompletedTask;
}
private async Task NavigationController_Init(object sender, InitEventArgs e)
diff --git a/TelegramBotBase/Interfaces/IStateForm.cs b/TelegramBotBase/Interfaces/IStateForm.cs
index 7e42cc4..0a713cb 100644
--- a/TelegramBotBase/Interfaces/IStateForm.cs
+++ b/TelegramBotBase/Interfaces/IStateForm.cs
@@ -1,4 +1,5 @@
-using TelegramBotBase.Args;
+using System.Threading.Tasks;
+using TelegramBotBase.Args;
namespace TelegramBotBase.Interfaces;
@@ -7,7 +8,7 @@ namespace TelegramBotBase.Interfaces;
///
public interface IStateForm
{
- void LoadState(LoadStateEventArgs e);
+ Task LoadState(LoadStateEventArgs e);
- void SaveState(SaveStateEventArgs e);
-}
\ No newline at end of file
+ Task SaveState(SaveStateEventArgs e);
+}
diff --git a/TelegramBotBase/SessionBase.cs b/TelegramBotBase/SessionBase.cs
index e7036cd..bd4f2bb 100644
--- a/TelegramBotBase/SessionBase.cs
+++ b/TelegramBotBase/SessionBase.cs
@@ -118,25 +118,25 @@ public class SessionBase
///
/// Loads the previously saved states from the machine.
///
- public async void LoadSessionStates()
+ public async Task LoadSessionStates()
{
if (BotBase.StateMachine == null)
{
return;
}
- LoadSessionStates(BotBase.StateMachine);
+ await LoadSessionStates(BotBase.StateMachine);
}
///
/// Loads the previously saved states from the machine.
///
- public async void LoadSessionStates(IStateMachine statemachine)
+ public async Task LoadSessionStates(IStateMachine statemachine)
{
if (statemachine == null)
{
- throw new ArgumentNullException("StateMachine",
+ throw new ArgumentNullException(nameof(statemachine),
"No StateMachine defined. Please set one to property BotBase.StateMachine");
}
@@ -230,7 +230,7 @@ public class SessionBase
{
Values = s.Values
};
- iform.LoadState(ls);
+ await iform.LoadState(ls);
}
try
@@ -251,11 +251,11 @@ public class SessionBase
///
/// Saves all open states into the machine.
///
- public void SaveSessionStates(IStateMachine statemachine)
+ public async Task SaveSessionStates(IStateMachine statemachine)
{
if (statemachine == null)
{
- throw new ArgumentNullException("StateMachine",
+ throw new ArgumentNullException(nameof(statemachine),
"No StateMachine defined. Please set one to property BotBase.StateMachine");
}
@@ -299,7 +299,7 @@ public class SessionBase
{
//Loading Session states
var ssea = new SaveStateEventArgs();
- iform.SaveState(ssea);
+ await iform.SaveState(ssea);
se.Values = ssea.Values;
}
@@ -335,7 +335,7 @@ public class SessionBase
///
/// Saves all open states into the machine.
///
- public void SaveSessionStates()
+ public async Task SaveSessionStates()
{
if (BotBase.StateMachine == null)
{
@@ -343,6 +343,6 @@ public class SessionBase
}
- SaveSessionStates(BotBase.StateMachine);
+ await SaveSessionStates(BotBase.StateMachine);
}
}