AssistoLab / KVNProgress

KVNProgress is a fully customizable progress HUD that can be full screen or not.
MIT License
1.24k stars 202 forks source link

Force KVNProgress to appear on the Main Thread #82

Open freak4pc opened 8 years ago

freak4pc commented 8 years ago

Hey All, I was wondering something for a while now.

KVNProgress will pretty much always crash if it's executed outside of the Main Thread. The current solution (which seems to be a recurring answer to issues here), would be to wrap the call with a GCD Dispatch on dispatch_get_main_queue().

My question here is, why not just enforce that to begin with? Why not have KVNProgress always display itself on the main thread, if it's not already there and avoid all of this confusion.

Even something as simple as:

if ([NSThread mainThread]) {
 // Execute as usual
} else {
  dispatch_async(dispatch_get_main_queue()) {
    // Execute as usual
  }
}

What are your thoughts on this? @kevin-hirsch

I wouldn't mind quickly making a pull request for this if there's a demand :)

freak4pc commented 8 years ago

@kevin-hirsch this has been open for over 2 months... Any thoughts ?

freak4pc commented 7 years ago

There is a great fork solving this very problem. Any chance you would consider adding this in? @kevin-hirsch : https://github.com/dmsl1805/KVNProgress/commit/318fe74872703575a72a234e0ba00248554a8e5c

NicosKaralis commented 5 years ago

2 years later I'm still having this problem

I've wrapped around the main thread but it still complains about updating UI on background thread

DispatchQueue.main.async {
  KVNProgress.show()
}

Apparently the problem is caused here: [self.contentView addMotionEffect:group];, maybe because dispatch_once does not run on main thread? What can we do?

KVNPrepareBlockSelf();
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
  [KVNBlockSelf setupMotionEffect];
});

I'm using swift 4.2 and the latest XCode