相关疑难解决方法(0)

System.Timers.Timer与System.Threading.Timer

我最近一直在查看一些可能的计时器,而Threading.TimerTimers.Timer对我来说是必要的(因为它们支持线程池).

我正在制作游戏,我计划使用不同类型的活动,间隔不同等.

哪个最好?

.net timer

541
推荐指数
6
解决办法
28万
查看次数

该应用程序称为为不同线程编组的接口--Windows Store App

所以,首先我已经阅读了大量关于这个特定问题的线索,我仍然不明白如何解决它.基本上,我正在尝试与websocket进行通信,并将收到的消息存储在绑定到listview的可观察集合中.我知道我正在从套接字中正确地获得响应,但是当它尝试将其添加到observable集合时,它会给我以下错误:

The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
Run Code Online (Sandbox Code Playgroud)

我已经阅读了一些关于"发送"以及其他一些事情的信息,但我只是大肆混淆!这是我的代码:

public ObservableCollection<string> messageList  { get; set; }
private void MessageReceived(MessageWebSocket sender, MessageWebSocketMessageReceivedEventArgs args)
    {
        string read = "";
        try
        {
            using (DataReader reader = args.GetDataReader())
            {
                reader.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
                read = reader.ReadString(reader.UnconsumedBufferLength);
            }
        }
        catch (Exception ex) // For debugging
        {
            WebErrorStatus status = WebSocketError.GetStatus(ex.GetBaseException().HResult);
            // Add your specific error-handling code here.
        }


        if (read != "")
           messageList.Add(read); // this is …
Run Code Online (Sandbox Code Playgroud)

c# xaml multithreading windows-store-apps

51
推荐指数
3
解决办法
4万
查看次数

标签 统计

.net ×1

c# ×1

multithreading ×1

timer ×1

windows-store-apps ×1

xaml ×1