c# - How to use callback string to mainform -



c# - How to use callback string to mainform -

i have method written in c#

class torrentdownload { private readonly thread _getstatethread; public sohadownload() { _getstatethread = new thread(getstate); _getstatethread.start(); } torrenthandle handle=null; public void start(addtorrentparams param) { var _session = new session(); if (_session == null) throw new argumentnullexception("sesion"); _session.listenon(6881, 6889); handle = _session.addtorrent(param); } public void getstate(){ while (true) { if (handle == null) { thread.sleep(1000); continue; } var status = handle.getstatus(); if (status.isseeding) { break; } string _state = status.state.tostring(); double _up = status.uploadrate; double _down = status.downloadrate; double _process = status.progress; thread.sleep(1000); //console.writeline("state {0} process {1}", _state, _process); } } }

now in main() programme want phone call value in _state, _up, _dơn, _process variable show in console.writeline trying utilize delegate it's not working.

please help me, thanks.

based on requirements, here idea

construct class manage status , create public properties in order enable access variables values

and main function can phone call getstate , can access values of _state, _up, _down, _process

you can create properties , method , class static if want, here sample code:

public class managestatus { private string _state; private double _up,_down,_process; public string state { get{ homecoming _state;} set{ _state=value;} } public string state { get{ homecoming _state;} set{ _state=value;} } public double { get{ homecoming _up;} set{ _up=value;} } public double downwards { get{ homecoming _down;} set{ _down=value;} } public double process { get{ homecoming _process;} set{ _process=value;} } public void getstate() { while (true) { if (handle == null) { thread.sleep(1000); continue; } var status = handle.getstatus(); if (status.isseeding) { break; } _state = status.state.tostring(); _up = status.uploadrate; _down = status.downloadrate; _process = status.progress; thread.sleep(1000); } } }

and in main code can this

public static void main() { var status=new managestatus(); status.getstate(); console.writline("state:{0}",status.state); console.writline("up:{0}",status.up); console.writline("down:{0}",status.down); console.writline("process:{0}",status.process); }

hope help you

c# .net

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -