Dev blog

C# Developer and a Geek

Currently Viewing Posts in wpf

How too use Tasks and progressbar in .net

Everybody know how nice Task can be to work with, but did you know there is actually a interface for using a progressbar.
I will show you how to use it and how to implement it and make use of it.

First of we start with write a class i called it ProgressClass with a int this will contain our reported progress.
You can extend this class to contain anything you like that has todo with the progress reporting for example maybe you want to set Max value to your progressbar you could do this with an extra field in ProgressClass if you like to.
But lets focus on reporting the progress only.

1
2
3
4
public class ProgressClass
{
     public int Progress { get; set; }
}

next up we need code for our progress and in C# there is already a class for this under System namespace called Progress that has an EventHandler called ProgressChanged that is what we need.
Lets take a look at the example code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
private void Init()
{
var progress = new Progress<ProgressClass>();
progress.ProgressChanged += Progress_Changed;
StartTask(progress);
}

private void StartTask(IProgress<ProgressClass> progress)
{
    Task myTask = Task.Run(() =>
    {
        try
        {
                     for (int i = 0; i < 100; i++)
                     {
                        progress.Report(new ProgressClass { Progress = i+1 });
                        Thread.Sleep(100);
                     }
        }
        catch (Exception crap)
        {
            //Handle Exceptions!
        }
    });
}

private void Progress_Changed(object sender, ProgressClass e)
{
     MyProgressBar.Value = e.Progress;
}

So this is a very easy implementation to use a Progressbar for your .net application.

Have a nice weekened

Working on a small utility to push emails to apis

Lately been working on a small utility to push emails to any kind of api, anyone can create a api integration in the software.

You get all the information from the software and for now we have support for OsTicket api, but i will look into to add support for Katak support to, but there is probobly plenty more to work on also, such as attachment im pretty sure thats not completed either yet.

Good thing is that this is my first open source software the source code is on github: https://github.com/neisep/emailpipe

The code is yet little bit messy but im working to clean it up and move stuff around, feel free too modify or help out on it if you wish.

 

 

C# relay server

Created a small small relay server, right now it only works with text and the concept is that a client connect too a server with a key and password to connect to another server.

So basicly this will replace my old junkie Support tool later on.

But we will see