windows phone 7 - How to disable BackgroundTransferRequest's TransferStatusChanged event handler after I unsubscribed it? -
i'm using background transfer download videos , subscribed each request's transferstatuschanged , transferprogresschanged event monitor it's status , download progress. when cancelled 1 background transfer request using backgroundtransferservice.remove() method, fired transferstatuschanged event as msdn mentioned. don't want execute event handlers, try unsubscribe event before removed request, code below:
backgroundtransferrequest transfertoremove = backgroundtransferservice.find(requestid); if (transfertoremove != null) { transfertoremove.transferstatuschanged -= transfer_transferstatuschanged; transfertoremove.transferprogresschanged -= transfer_transferprogresschanged; backgroundtransferservice.remove(transfertoremove); }
but transferstatuschanged event handler still fired. can me?
backgroundtransferservice.remove(transfertoremove); accepts request. take sometime remove it. meanwhile, again call add() function , got 1 more event i.e. transfer_transferprogresschanged.
in event transfer_transferprogresschanged, first check backgroundtransferservice contains request or not.
if(backgroundtransferservice.requests.contains(m_currentrequest)) { backgroundtransferservice.remove(m_currentrequest); unsubscribeyourevents(); dootherstuffrealtedtodownload(); }
Comments
Post a Comment