Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void ReadAsync<T>(AsyncReadCallback<T> callback, AsyncException exception = null) {
- try {
- Thread thread = new Thread(new ThreadStart(() => {
- try {
- T request = ReadSync<T>();
- callback.Invoke(ref request);
- } catch(Exception e) {
- if(exception == null) {
- throw e;
- }
- exception.Invoke(e);
- }
- }));
- thread.Start();
- } catch (Exception e) {
- if(exception == null) {
- throw e;
- }
- exception.Invoke(e);
- }
- }
- stream.ReadAsync((string result) => {
- Console.WriteLine("receive: "+result);
- },(Exception e) => {
- Console.WriteLine("exception: "+e.Message);
- });
- public async Task<T> ReadAsync<T>() {
- return ReadSync<T>();
- }
- Task<string> taskRead = stream.ReadAsync<string>();
- ...
- string data = await taskRead;
- Console.WriteLine(data);
Add Comment
Please, Sign In to add comment