Forum

Results 1 to 5 of 5
  1. #1
    Join Date
    April 2018
    Posts
    3

    What's the best practice of using SDK asynchronously? (C#)

    Hi,
    I'm integrating TS3 SDK into my C#(WPF) project. I have tried several ways to use SDK asynchronously(Task, ThreadPool, etc) while I don't want to stuck UI process, but sometimes I got an InvalidOperationException. So I wonder if there is any sample code to do it right?
    Thanks.

    Hans

  2. #2
    Join Date
    September 2012
    Posts
    6,080
    The C# SDK Wrapper Examples may be worth looking at if you haven't done so yet.
    When sending PMs please make sure to include a reference link to the thread in question in the body of your message.

  3. #3
    Join Date
    April 2018
    Posts
    3
    Quote Originally Posted by Chris View Post
    The C# SDK Wrapper Examples may be worth looking at if you haven't done so yet.
    I have already read example code, but it's a windows console project and all operations are finished on main thread. I need some codes about how to do these operations in multi-thread way.

    Thanks you for your reply.

  4. #4
    Join Date
    September 2012
    Posts
    6,080
    The InvalidOperationExceptions you're getting are likely from your WPF code as the wrapper only throws that during initialization or when attempting to (dis)connect while a (dis)connect attempt in already in progress.
    Note that it is not guaranteed that an asynchronous operation resumes on the same thread it was called on.
    Last edited by Chris; April 9th, 2018 at 04:04 PM.
    When sending PMs please make sure to include a reference link to the thread in question in the body of your message.

  5. #5
    Join Date
    April 2018
    Posts
    3
    Quote Originally Posted by Chris View Post
    The InvalidOperationExceptions you're getting are likely from your WPF code as the wrapper only throws that during initialization or when attempting to (dis)connect while a (dis)connect attempt in already in progress.
    Note that it is not guaranteed that an asynchronous operation resumes on the same thread it was called on.
    Yeah, I have read the code about checking source with Interlocked. So I tried to use task.ContinueWith(...). Then that exception did disappear, but I did't figure out if all operations are required to be done on a same thread or only connect/disconnect do.

    Thanks for your patience.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •