csharp-sdk-upm/Sample/RealtimeApp/Program.cs

69 lines
2.1 KiB
C#
Raw Normal View History

using System;
2020-06-24 12:15:19 +08:00
using System.Threading.Tasks;
using LeanCloud;
using LeanCloud.Realtime;
using static System.Console;
namespace RealtimeApp {
class Program {
static void Main(string[] args) {
2020-06-24 12:15:19 +08:00
WriteLine("Hello World!");
SingleThreadSynchronizationContext.Run(async () => {
LCLogger.LogDelegate += Print;
LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
2020-06-24 12:15:19 +08:00
LCIMClient client = new LCIMClient("lean") {
OnPaused = () => {
WriteLine("~~~~~~~~~~~~~~~ disconnected");
},
OnResume = () => {
WriteLine("~~~~~~~~~~~~~~~ reconnected");
}
};
await client.Open();
2020-06-24 12:15:19 +08:00
int count = 0;
while (count < 2) {
WriteLine($"pause : {count}");
await Task.Delay(5 * 1000);
LCRealtime.Pause();
await Task.Delay(5 * 1000);
LCRealtime.Resume();
await Task.Delay(5 * 1000);
count++;
}
try {
await client.Close();
// Done
} catch (Exception e) {
WriteLine($"xxxxxxxxxxxx {e.Message}");
}
});
}
static void Print(LCLogLevel level, string info) {
switch (level) {
case LCLogLevel.Debug:
WriteLine($"[DEBUG] {DateTime.Now} {info}\n");
break;
case LCLogLevel.Warn:
WriteLine($"[WARNING] {DateTime.Now} {info}\n");
break;
case LCLogLevel.Error:
WriteLine($"[ERROR] {DateTime.Now} {info}\n");
break;
default:
WriteLine(info);
break;
}
}
}
}