Better way is to return information from your library to main program/form. Then update controls inside form. Doing this way you have loosely coupled architecture, and you can separate your layers. Libray doesn't need to know about your forms which and you can reuse your Library code. Try to use this simple approach:
public bool DeletePrefs()
{
try
{
bool result = false;
String StrFile = @"C:\Program Files\X\Workspace\prefs.txt";
if (File.Exists(StrFile))
{
File.Delete(StrFile);
result = true;
}
}
catch (IOException ex)
{
}
catch (...)
{
}
finally
{
}
return result;
}
And calling your class should be:
private void StartCmd_Click(object sender, EventArgs e)
{
Library lib = new Library();
lib.StopService();
if (lib.DeletePrefs())
{
pFileStatus.ForeColor = System.Drawing.Color.Black;
pFileStatus.Text = "Deleted";
}
else
{
MessageBox.Show("Error while deleting prefs file");
}
}
If you need to return additional error informations you can create your
custom exceptions or rethrow
standard exceptions to inform your library consumer about it.
More informations you can find here:
http://msdn.microsoft.com/en-us/library/vstudio/ms229042%28v=vs.100%29.aspx[
^]
http://msdn.microsoft.com/en-us/library/vstudio/ms229014%28v=vs.100%29.aspx[
^]
I hope you find this useful :)