async task running twice if I run it immediately after startup...

JKnottJKnott Member ✭✭✭

Hello all, I need some serious help here...
I have some async tasks that I need to be thread safe, so I have made sure to make their declarations private async Task function() and I am ensuring that I call them using the await command, but if I run the function immediately after my app starts, I get multiple threads entering. To make matters more bizarre if I wait for some time, and watch the output in VS, eventually I see a number of threads and thread groups complete, then when I run my task, it performs as I had expected... All I can think of is that the app is "settling" and that other threads from other areas are completing and somehow resuming along my thread path hence entering my async function....
I need to know if this sounds like a real possibility (or am I crazy here), and if this is a possibility (It has to be, other wise I doubt all that is real and my own existence as real) I need to know if anyone has a good tutorial on how to implement a thread monitor/splash screen that I can use to trace my threads, and report when they have settled (thus safe to resume the application). Alternately if this is not a possibility, I assume that there is a Lock method of some sort I can use? although I wonder if it would work since the threads are colliding and could hang or crash the app....

Any guidance would be MOST appreciated!

Best Answer

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    You should post some code
  • JohnHardmanJohnHardman GBUniversity mod
    edited August 13

    @JKnott - As per the forum rules & guidelines at https://forums.xamarin.com/discussion/87290/xamarin-forum-rules-and-guidelines#latest , posts should not include "vulgarity". Please edit your previous post to remove profanity (code comments).

  • JohnHardmanJohnHardman GBUniversity mod

    @JohnHardman said:
    @JKnott - As per the forum rules & guidelines at https://forums.xamarin.com/discussion/87290/xamarin-forum-rules-and-guidelines#latest , posts should not include "vulgarity". Please edit your previous post to remove profanity (code comments).

    As your post is now over 4 hours old, you won't be able to edit it. I'm going to leave it there until end of day so that you have time to copy, edit and re-post. After that, I'll be deleting the post.

  • JKnottJKnott Member ✭✭✭

    @JohnHardman Sorry about the comment, I was copying code from my source, and forgot to screen the comments. Please accept my appology for the crass comments, I did not intend to post those...

  • JKnottJKnott Member ✭✭✭

    @Alfonsi Excellent, I think that should take care of the threading problem.
    Thanks!

  • JKnottJKnott Member ✭✭✭

    @JohnHardman May I ask why there is a 4 hour limit on editing posts? also why can I not delete my post?

  • JohnHardmanJohnHardman GBUniversity mod

    @JKnott said:
    @JohnHardman May I ask why there is a 4 hour limit on editing posts? also why can I not delete my post?

    Both are things that I, as a moderator, have no control over. TBH, I'm not sure even the administrators have control over those bits.

    I don't know where the 4 hour time limit came from. I've certainly had occasions where I've wanted to edit a post but couldn't because of the limit.

    I also don't know the logic for not allowing posts to be deleted by their posters. However, there are definite benefits to not allowing deletions. It stops people from asking questions, getting an answer, then deleting the post. If people did that (and some have asked for deletions to occur as they had an answer, something I won't do), then the forums would be more like Snapchat than a repository of useful information.

  • JKnottJKnott Member ✭✭✭

    @JohnHardman Definitely, I love that I can see previous discussions, and learn from them. I guess some people may not have the same ideology of wanting to let others learn from the guidance they themselves got. It's a shame really.
    I too have been bitten by the 4 hour limit as well (more than once now, again I am sorry for that oversight).
    In the end I'm just glad this community is here and look forward to learning, and participating more in the future.

Sign In or Register to comment.