PCDVD數位科技討論區
(https://www.pcdvd.com.tw/index.php)
- 疑難雜症區
(https://www.pcdvd.com.tw/forumdisplay.php?f=34)
- - 請教關於 C# 修改原始碼問題
(https://www.pcdvd.com.tw/showthread.php?t=1181838)
|
---|
請教關於 C# 修改原始碼問題
這是吃 .NET 4.5 的 要用 Visual Studio 2012 以上的版本才能編譯
代碼:
public async Task SendAsync(PacketReader reader) { .... try { await this._socket.SendTaskAsync(buffer); } catch (Exception ex1) { .... return; } this._isSending = false; } public async Task ReceiveAsync() { .... try { int taskAsync = await this._socket.ReceiveTaskAsync(receiveBuffer); } catch (Exception ex) { .... return; } } 我想要把他降級到吃 .Net 3.5 的版本,但是.Net 3.5 沒 async 跟 await 該用什麼替代? async Task SendAsync(PacketReader reader) async Task ReceiveAsync() await this._socket.SendTaskAsync(buffer); await this._socket.ReceiveTaskAsync(receiveBuffer); 這四行如果改吃 .Net 3.5 或 .Net 2.0 以下版本,該怎麼寫? 我想讓他能在 Winsows XP 底下跑 :D |
|
引用:
async await 這是 .net 4.5 的, 3.5 沒這個 :think: |
放棄 3.5 改用 4.0暫時得到緩解,編譯成功測試可以用 :D :D
代碼:
public async Task SendAsync(PacketReader reader) // .Net 4.5 改成 public void SendAsync(PacketReader reader) // 都可以 { .... try { await this._socket.SendTaskAsync(buffer); 改成 this._socket.SendTaskAsync(buffer).Wait(); } catch (Exception ex1) { .... return; } } public async Task ReceiveAsync() // .Net 4.5 改成 public async Task ReceiveAsync() // 都可以 { .... try { int taskAsync = await this._socket.ReceiveTaskAsync(receiveBuffer); 改成 this._socket.ReceiveTaskAsync(receiveBuffer).Wait(); } catch (Exception ex) { .... return; } } |
二天一流 *台法機乖分身帳號
https://www.pcdvd.com.tw/member.php?u=343600 水土散熱器都實作不了的伸手廢物 還來鬧笑話 :laugh: :laugh: :laugh: |
所有的時間均為GMT +8。 現在的時間是01:20 AM. |
vBulletin Version 3.0.1
powered_by_vbulletin 2024。