private void SyncRun(object state) { Action action = ((RunContent)state).Action; object body = ((RunContent)state).Body; switch (action) { case Action.SetStatus: SetStatusParam param = (SetStatusParam)body; _logger.Add(param.Message, param.ToMessage, param.IsError); break; case Action.IsUpdaterTrue: ((Author)body).IsUpdated = true; break; case Action.IsUpdaterFalse: ((Author)body).IsUpdated = false; break; case Action.UpdateAuthorText: UpdateTextParam updateTextParam = (UpdateTextParam)body; if (updateTextParam.IsNew) { _logger.Add(string.Format("{1}/{2}: '{0}' обновлен", updateTextParam.Author.Name, updateTextParam.Index, updateTextParam.Count)); if (_baloonInfo == "") { _baloonInfo = "Обновились авторы:\n"; } _baloonInfo = _baloonInfo + updateTextParam.Author.Name + "; "; } break; case Action.CachedAdd: CachedParam cachedParamAdd = (CachedParam)body; DownloadTextItem item = DownloadTextHelper.Add(cachedParamAdd.Author, cachedParamAdd.AuthorText); if (item.Text == null) { item.Start(); } cachedParamAdd.DownloadTextItem = item; break; case Action.CachedRemove: CachedParam cachedParamRemove = (CachedParam)body; cachedParamRemove.DownloadTextItem.Stop(); break; default: throw new ArgumentOutOfRangeException("state"); } }
/// <summary> /// Выполняет действие в контексте gui потока /// </summary> /// <param name="action">Действие</param> /// <param name="body">Параметры действия</param> private void SyncRun(Action action, object body) { switch (action) { case Action.UpdateAuthorText: { UpdateTextParam updateTextParam = (UpdateTextParam)body; updateTextParam.IsNew = updateTextParam.Author.UpdateAuthorInfo(updateTextParam.Page, _syncContext); _syncContext.Post(SyncRun, new RunContent(action, updateTextParam)); } break; case Action.CachedAdd: //синхронный, т.к. надо получить ответ в CachedParam.DownloadTextItem _syncContext.Send(SyncRun, new RunContent(action, body)); break; default: _syncContext.Post(SyncRun, new RunContent(action, body)); break; } }