I have a main form which does processing for an extended period of time. Normally, progress bars are used to show either the loading status or simply show the program is still running/hasn't freezed.

For this form, I wanted to give it a more snazzy look by reusing a common loading GIF found on the web that many users would be familiar with.

This is how I implement said GIF:

ShowLoadingGif();

//Heavy lifting

{
this.Enabled = false;

Point formCenterPt = new Point()
{
X = this.Location.X + (this.Width/2),
Y = this.Location.Y + (this.Height/2)
};

}

{
try
{
this.Enabled = true;
}
catch (Exception ex)
{
}
}

{

Point offsetPt = new Point()
{
};

}


What this does is produces a loading GIF (I grabbed mine from ajaxloader) in the center of the form while processing is ongoing, and also disables the form.

My question is, whether or not what I did was overkill for something as simple as an inprogresss status, or if using threads in this way is the best way to do it. I realize that using a control on the main form would have been easier, but I couldn't find a way to do so with a GIF while also making the background completely transparent.

Why have I chosen to use a form for showing the GIF?

The alternative would have been to add the picture box to the main form. However, this didn't seem the best solution because I wanted to center the GIF to the form itself, and with the TableLayoutPanel I was using, you can't simply change the location of a control in that manner (please correct me if I'm wrong here). I also wanted to keep the transparency, threading, and other attributes of the picturebox control separate from the main form so I could reuse it elsewhere.

Finally, I wanted to show the GIF loading on top of the current form, and not just in the corner/bottom in its own section like a progress bar would. As you'll see in the picture, the loading GIF is shown on top of the control behind it, a DataGridView.

I don't know much about threading, so I can't really comment on that, but there is an opportunity to extract some logic that I am sure is used elsewhere in your project. You have this in ShowLoadingGif()

Point formCenterPt = new Point()
{
X = this.Location.X + (this.Width/2),
Y = this.Location.Y + (this.Height/2)
};


And this in ShowLoading()

Point offsetPt = new Point()
{
};


I would create two functions that take a form as an argument and return a point representing the StartingPosition and center point respectively.

I'm not a fan of this If statement.

try
{
this.Enabled = true;
}


First off, at the very least, loadingThread.Abort needs to be indented properly.

if(loadingThread.IsAlive)


But I still don't like it. Let's say down the road Mr. Maintainer realizes that something else should happen if(loadingThread.IsAlive. Then they do something like this.

if(loadingThread.IsAlive)
foo.bar();


The problem here is, foo.bar() will always be executed, but it looks like it will only be executed if(loadingThread.IsAlive).

So, there are really only two options in my mind.

1. Write it as a single line If statement.

if (loadingThread.IsAlive) loadingThread.Abort();

2. Or put the braces in.

if (loadingThread.IsAlive)
{

catch (Exception ex)