Correctly Dispose native resources in C# example.
GitOrigin-RevId: 60f0720dcac4da811da30e26e834670d62d1a42f
This commit is contained in:
parent
3204e9f26c
commit
83e28b8ebc
@ -28,7 +28,7 @@ namespace TdExample
|
|||||||
private static volatile AutoResetEvent _gotAuthorization = new AutoResetEvent(false);
|
private static volatile AutoResetEvent _gotAuthorization = new AutoResetEvent(false);
|
||||||
|
|
||||||
private static readonly string _newLine = Environment.NewLine;
|
private static readonly string _newLine = Environment.NewLine;
|
||||||
private static readonly string _commandsLine = "Enter command (gc <chatId> - GetChat, me - GetMe, sm <chatId> <message> - SendMessage, lo - LogOut, q - Quit): ";
|
private static readonly string _commandsLine = "Enter command (gc <chatId> - GetChat, me - GetMe, sm <chatId> <message> - SendMessage, lo - LogOut, r - Restart, q - Quit): ";
|
||||||
private static volatile string _currentPrompt = null;
|
private static volatile string _currentPrompt = null;
|
||||||
|
|
||||||
private static Td.Client CreateTdClient()
|
private static Td.Client CreateTdClient()
|
||||||
@ -123,6 +123,7 @@ namespace TdExample
|
|||||||
else if (_authorizationState is TdApi.AuthorizationStateClosed)
|
else if (_authorizationState is TdApi.AuthorizationStateClosed)
|
||||||
{
|
{
|
||||||
Print("Closed");
|
Print("Closed");
|
||||||
|
_client.Dispose(); // _client is closed and native resources can be disposed now
|
||||||
if (!_quiting)
|
if (!_quiting)
|
||||||
{
|
{
|
||||||
_client = CreateTdClient(); // recreate _client after previous has closed
|
_client = CreateTdClient(); // recreate _client after previous has closed
|
||||||
@ -172,6 +173,10 @@ namespace TdExample
|
|||||||
_haveAuthorization = false;
|
_haveAuthorization = false;
|
||||||
_client.Send(new TdApi.LogOut(), _defaultHandler);
|
_client.Send(new TdApi.LogOut(), _defaultHandler);
|
||||||
break;
|
break;
|
||||||
|
case "r":
|
||||||
|
_haveAuthorization = false;
|
||||||
|
_client.Send(new TdApi.Close(), _defaultHandler);
|
||||||
|
break;
|
||||||
case "q":
|
case "q":
|
||||||
_quiting = true;
|
_quiting = true;
|
||||||
_haveAuthorization = false;
|
_haveAuthorization = false;
|
||||||
|
Reference in New Issue
Block a user