small problem in my c# project

hi and sorry about my next bad english :slight_smile:

i want to make a small tool look like winbox using c# api class and this the class link

[u]http://wiki.mikrotik.com/wiki/API_in_C_Sharp[/u]

but when i add a code inside a timer to update cpu-load and uptime every 5 second the form hang’s and freeze for a moment every time the timer trying to send a command to the mikrotik server

that’s main my application will stop and hang for 1 second every time the timer will send the command to the server

this is my timer code

private void ResourcesTimer_Tick(object sender, EventArgs e)
        {
            MK API = new MK(addr);
                if (API.Login(user, pass))
                {
                    API.Send("/system/resource/print", true);
                    foreach(string r in API.Read()){
                    
                    	// update cpu-load and uptime
                    
                    }
                    
                    API.Close();
                 }
          }

so any one can help me to solve this problem or tell my what is the reason ?

thank you and i hope I was able to explain my problem in the right way :slight_smile:

Any Help ??

I suggest you look into Threads.

EDIT: Actually, I noticed timers have an option to run the event in an external thread… Just do THAT then I guess.

It’s normal for any network activity (especially one outside the local network) to take a second, and if you run that inside the main application thread (which is the UI thread), then it’s normal for the UI to block while that’s happening.

What you need to do is make the connection and refreshes at a separate thread that then asks the UI thread to update with the new info. This will keep the UI thread responsive in between, letting users click and what not.

Also, keep the connection opened! Don’t log in every 1 second just to refresh the timer. The login itself is your biggest performance penalty.

boen_robot i love you man you are the only one here who are always reply to my questions :slight_smile:

thank you and i will try your solution