i have 4 if
statements in code change displays. on if
statement inqueueinring > 10
cycle every .5 seconds between red, yellow, , green images until condition no longer true. i'm not sure start cycling images. list image source multiple times thread.sleep(1000)
in between them?
i tried use loading new image each second can't convert type system.threading.timer system.windows.media.imagesource. updated code below.
below if
statements
if (e.cmsdata.skill.agentsavailable > 0) { dispatcher.begininvoke(dispatcherpriority.normal, (action)(() => { callswaitingdata.text = e.cmsdata.skill.agentsavailable.tostring(); callswaitingdata.foreground = new solidcolorbrush(colors.green); callswaitingtext.text = "available"; callimgae.source = new bitmapimage(new uri("pack://application:,,,/scoreboardclienttest;component/images/circle_green.png", urikind.absolute)); })); } else if (e.cmsdata.skill.inqueueinring > 10) { dispatcher.begininvoke(dispatcherpriority.normal, (action)(() => { callswaitingdata.text = e.cmsdata.skill.inqueueinring.tostring(); callswaitingdata.foreground = new solidcolorbrush(colors.red); callswaitingtext.text = "waiting"; timer = new system.threading.timer(ontimerellapsed, new object(), 0, 2000); })); } else if (e.cmsdata.skill.inqueueinring > 0) { dispatcher.begininvoke(dispatcherpriority.normal, (action)(() => { callswaitingdata.text = e.cmsdata.skill.inqueueinring.tostring(); callswaitingdata.foreground = new solidcolorbrush(colors.red); callswaitingtext.text = "waiting"; callimgae.source = new bitmapimage(new uri("pack://application:,,,/scoreboardclienttest;component/images/circle_red.png", urikind.absolute)); })); } else if (e.cmsdata.skill.agentsavailable == 0) { dispatcher.begininvoke(dispatcherpriority.normal, (action)(() => { callswaitingdata.text = e.cmsdata.skill.agentsavailable.tostring(); callswaitingdata.foreground = new solidcolorbrush(colors.yellow); callswaitingtext.text = "available"; callimgae.source = new bitmapimage(new uri("pack://application:,,,/scoreboardclienttest;component/images/circle_yellow.png", urikind.absolute)); })); } private void ontimerellapsed(object state) { if (!this.dispatcher.checkaccess()) { this.dispatcher.invoke(new action(loadimages)); } } private void loadimages() { string stringuri = switcher ? @"pack://application:,,,/scoreboardclienttest;component/images/circle_red.png" : @"pack://application:,,,/scoreboardclienttest;component/images/circle_yellow.png"; // @"pack://application:,,,/scoreboardclienttest;component/images/circle_green.png"; this.callimgae.source = new bitmapimage(new uri(stringuri)); switcher = !switcher; }
so can't see rest of code, if going use these images sure pre-load or cache them somewhere before doing kind of operation (for performance).
there plenty of threading/process classes can use bare bones 1 enjoy using thread class. here how set thread..
thread mythread = new thread(threaddelegate);
the threaddelegate of class threadstart the work want thread do. here 1 way set threaddelegate..
threadstart threaddelegate = new threadstart(() => { while (iscycling == true) { // code here thread.sleep(1000); } });
the iscycling loop stop on condition after odd cycles or prematurely exit. can make thread start delegate/work gave using start method..
mythread.start();
if want parent thread (i.e. main thread) wait thread stop or not move on until cycling done can use join method on mythread.
Comments
Post a Comment