適切

2017-07-15 11 views
0

私は不和のボットを使用している、と私は、タイムサービスの時間を確認しようとしているが、そのだけ一度だけの時間を示し、その後、0適切

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(); 
} 
を書き込み

この関数を呼び出す

+0

新しいスレッドを開始した直後にストップウォッチをリセットしています。これは、他のスレッドが値をチェックすると、ストップウォッチが既にリセットされていることを意味します。 – Fruchtzwerg

+0

タイマーをリセットした後に 'time.Start();'がありませんか? –

答えて

0

非同期関数内でタイマーを作成してみてください。

+0

私はそれをあなたに感謝します。 –