How to make a for run in async mode?

I know it sounds dumb but i really tried using async methods with tasks and stuff but i guess thats not what i want.

All i want is to run a for in another thread soh my app can still run in peace...
What is the simplest way for me to do that?

Posts

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭

    Do you want to know when the work is done? If so, put the code you want to in another method and call it via the async/await pattern.

    If you just want it to run in another thread and don't care about when it is done there are a lot of ways to that including Task.Run.

  • HiltonMenezesHiltonMenezes BRMember ✭✭

    Yeah i dont want to know when its done, i just want to get it done...

    Can you give me a little sample about how to use Task.Run?

  • HiltonMenezesHiltonMenezes BRMember ✭✭

    im using

    var taskA = new Task ( () => {  findIpServer(); });
    taskA.Start();
    

    How many of this can i run at same time?

  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    Sounds like you need a bit of a tutorial on async/await. Have you seen Xamarin's documentation on async/await support? For some more in depth information, I found the book Async in C# 5.0 to be a good, light read.

  • HiltonMenezesHiltonMenezes BRMember ✭✭

    And yes i did

  • KevinFordKevinFord USUniversity, Certified XTC Partners ✭✭✭

    If you just want to kick off a task on another thread in the thread pool and don't care about when it is done you can simply call:

    Task.Run( () => { Code I want to run async } );

    Of course there are a lot of ways to get code to execute on another thread, this is just one.

Sign In or Register to comment.