2017-07-15 7 views
0

Ich verwende Zwietracht bot, und ich versuche, die Zeit des Zeitdienstes zu überprüfen, aber seine zeigt nur die nur einmal Zeit und schreibt dann 0Stoppuhr und es funktioniert nicht richtig

public async Task HandleCommand(SocketMessage messageParam) 
{ 
    // Don't process the command if it was a System Message 
    var message = messageParam as SocketUserMessage; 

    if (message == null || message.Author.IsBot) 
     return; 

    Console.WriteLine(message.Author); 
    time.Start(); 

    // Create a number to track where the prefix ends and the command begins 
    int argPos = 0; 

    // Determine if the message is a command, based on if it starts with '!' or a mention prefix 
    if (!(message.HasCharPrefix('>', ref argPos))) 
     return; 

    // Create a Command Context 
    var context = new CommandContext(dbot, message); 
    Last = message.Author; 

    // Execute the command. (result does not indicate a return value, 
    // rather an object stating if the command executed successfully) 
    var result = await commands.ExecuteAsync(context, argPos, services); 

    time.Stop(); 
    time.Reset(); 
} 

und ruft diese Funktion

[Command("ping"), Summary("Echos a message.")] 
public async Task Say() 
{ 
    // ReplyAsync is a method on ModuleBase 
    await ReplyAsync("PONG " + CommandHandler.time.ElapsedMilliseconds); 
} 
+0

Sie setzen die Stoppuhr direkt nach dem Start des neuen Threads zurück. Dies bedeutet, dass die Stoppuhr bereits zurückgesetzt wurde, wenn der andere Thread den Wert überprüft. – Fruchtzwerg

+0

Fehlt Ihnen nach dem Zurücksetzen des Timers ein 'time.Start();'? –

Antwort

0

Versuchen Sie, Timer innerhalb Async-Funktion zu erstellen.

+0

Ich bekomme es Danke Jungs –