home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Background worker (to prevent freezing)
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Dragy" data-source="post: 754313" data-attributes="member: 91197"><p>I have made some progress with it and this is working, but is this the right way to do?</p><p>I have some kind of feeling this is not the way to use it.</p><p></p><p>[code]protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType)</p><p> {</p><p> if (control == buttonDevices)</p><p> {</p><p> bw_get = new BackgroundWorker();</p><p></p><p> GUIWaitCursor.Show();</p><p> bw_get.RunWorkerAsync();</p><p> bw_get.DoWork += bw_getDevices;</p><p> bw_get.RunWorkerCompleted += bw_getDevices_Completed;</p><p> //bw_get.ProgressChanged += bw_getDevices_ProgressChanged;</p><p></p><p> GuiList.Clear();</p><p></p><p> activeType = HCB.type.device;</p><p> GUIPropertyManager.SetProperty("#hcb.activeType", "Devices");</p><p> }</p><p>..........</p><p>[/code]</p><p></p><p>[code] void bw_getDevices(object sender, DoWorkEventArgs e)</p><p> {</p><p> try</p><p> {</p><p> e.Result = h.getDevices(); // This gets passed to RunWorkerCompleted</p><p> }</p><p> catch (Exception ex)</p><p> {</p><p> Log.Error("bw_getDevices: " + ex.Message);</p><p> }</p><p> }</p><p></p><p> void bw_getDevices_Completed(object sender, RunWorkerCompletedEventArgs e)</p><p> {</p><p> </p><p> try</p><p> {</p><p> devicesList = (SortedList)e.Result;</p><p></p><p> foreach (device d in devicesList.Values)</p><p> {</p><p> GUIListItem item = new GUIListItem();</p><p> item.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(listSelectDevice);</p><p> item.Label = d.name;</p><p> item.Label2 = d.type;</p><p> item.ItemId = d.id;</p><p> item.IsPlayed = d.status;</p><p></p><p> GuiList.Add(item);</p><p> }</p><p> GUIPropertyManager.SetProperty("#itemcount", GuiList.Count.ToString());</p><p> Log.Info("HCB: Devices listed");</p><p></p><p> GUIWaitCursor.Hide();</p><p> }</p><p> catch (Exception ex)</p><p> {</p><p> Log.Error("bw_getDevices_Completed: " + ex.Message);</p><p> }</p><p> }[/code]</p><p></p><p>Download whole project here: <a href="http://dl.dropbox.com/u/21558454/MP_HomeControlBox.zip" target="_blank">http://dl.dropbox.com/u/21558454/MP_HomeControlBox.zip</a></p><p></p><p>I hope it's all alright now <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile :)" loading="lazy" data-shortname=":)" /> But there is a big chance that my coding is all wrong..</p><p>Give me some feedback please.</p></blockquote><p></p>
[QUOTE="Dragy, post: 754313, member: 91197"] I have made some progress with it and this is working, but is this the right way to do? I have some kind of feeling this is not the way to use it. [code]protected override void OnClicked(int controlId, GUIControl control, MediaPortal.GUI.Library.Action.ActionType actionType) { if (control == buttonDevices) { bw_get = new BackgroundWorker(); GUIWaitCursor.Show(); bw_get.RunWorkerAsync(); bw_get.DoWork += bw_getDevices; bw_get.RunWorkerCompleted += bw_getDevices_Completed; //bw_get.ProgressChanged += bw_getDevices_ProgressChanged; GuiList.Clear(); activeType = HCB.type.device; GUIPropertyManager.SetProperty("#hcb.activeType", "Devices"); } .......... [/code] [code] void bw_getDevices(object sender, DoWorkEventArgs e) { try { e.Result = h.getDevices(); // This gets passed to RunWorkerCompleted } catch (Exception ex) { Log.Error("bw_getDevices: " + ex.Message); } } void bw_getDevices_Completed(object sender, RunWorkerCompletedEventArgs e) { try { devicesList = (SortedList)e.Result; foreach (device d in devicesList.Values) { GUIListItem item = new GUIListItem(); item.OnItemSelected += new MediaPortal.GUI.Library.GUIListItem.ItemSelectedHandler(listSelectDevice); item.Label = d.name; item.Label2 = d.type; item.ItemId = d.id; item.IsPlayed = d.status; GuiList.Add(item); } GUIPropertyManager.SetProperty("#itemcount", GuiList.Count.ToString()); Log.Info("HCB: Devices listed"); GUIWaitCursor.Hide(); } catch (Exception ex) { Log.Error("bw_getDevices_Completed: " + ex.Message); } }[/code] Download whole project here: [url]http://dl.dropbox.com/u/21558454/MP_HomeControlBox.zip[/url] I hope it's all alright now :) But there is a big chance that my coding is all wrong.. Give me some feedback please. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
MediaPortal 1
Development
General Development (no feature request here!)
Background worker (to prevent freezing)
Contact us
RSS
Top
Bottom