DispatchQueue freezed main queue

221 views Asked by At

I need to do some methods one by one without interrupting, in a separate thread, that way I have in my class

fileprivate var queue = DispatchQueue(label: "ProgressHUD", qos: .userInteractive)

and when I need show/hide I do some like this

queue.sync {
    __hide()
}

or

queue.sync {
    __show()
}

in this __%%() methods, I need to do some actions with UI in the main thread, and I need to do all action from --show/--hide one by one without interrupting. So in inner, I use

private func __show()
{
    let g = DispatchGroup()
    g.enter()
    DispatchQueue.main.async {
        print("go?")
        self.doMyAction1()
        self.doMyAction2()
        self.doMyAction3()

        g.leave()
    }
    g.wait()
}

but the app always freezes on line g.wait() and doesn't call main.async and doesn't print go?. What I do wrong!?

1

There are 1 answers

1
Anand Khanpara On
func dispatchGroup() -> String {

   var message = ""

   let group = DispatchGroup()

   group.enter()

   DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + 5) {
        message = "Hiii Friends"
        group.leave()
   }

   group.wait()

   return message
}