Alex E.
asked on
ASP.NET C# MessageBox.Show Showing a modal dialog box or form when the application ...
Someone helped us here with this cod to ctach an exception and pop up a message to the user with this code:
However when the message MessageBox.Show("File is in use"); is launched the applciation gives this error:
"Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application"
How can be fixed the problem or what could be the problem?
Thank you
private void button1_Click(object sender, EventArgs e)
{
lineChanger("QWERTY", "MyTextFile.txt", 2);
}
static void lineChanger(string newText, string fileName, int line_to_edit)
{
int attemptCounter = 0;
for (attemptCounter = 1; attemptCounter <= 10; attemptCounter++)
{
try
{
System.Diagnostics.Debug.WriteLine("Attempt " + (attemptCounter));
string[] arrLine = File.ReadAllLines(fileName);
arrLine[line_to_edit - 1] = newText;
File.WriteAllLines(fileName, arrLine);
// No error - break
break;
}
catch (IOException ioex)
{
System.Diagnostics.Debug.WriteLine("IOException happened: " + ioex.ToString());
if (attemptCounter >= 10)
{
MessageBox.Show("File is in use");
}
}
}
}
However when the message MessageBox.Show("File is in use"); is launched the applciation gives this error:
"Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application"
How can be fixed the problem or what could be the problem?
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you