Here's my function that I use to show print dialog (I write on C#). It was working nicely, when i wrote it. The problem is - since some day this code keeps only freezing my app instead of any printing. I tried also Show() with all 30 Missing params, but it doesn't make any change.
public bool Print()
{
var f1 = _application.Dialogs;
var f2 = f1[Excel.XlBuiltInDialog.xlDialogPrint];
bool DidntCancel = f2.Show();
return DidntCancel;
}
Freezing happens in f2.Show() call. My app window keeps refreshing it's view, but I can't click on anything. A tried to go into Show() method assembler lines via ste-by-step debug, but program doesn't go there, it dies exactly on the moment of method call.
Any help is very appreciated :)
Related
Using Visual Studio 2019, with an old C# Winforms .NET 4.6.2 application: I have a situation where my main form is acting as if it is being blocked by a modal:
Makes a beeping sound and flashes when clicking anywhere
Will not accept focus
Timer and serial communication Events are still triggering
No grey screen overlay, or message about the application ever becoming unresponsive
However, I can see no modal form, and using Application.OpenForms doesn't show any of the modals that I have created and have closed a few seconds previously.
I can successfully attach and debug remotely, that is how I know the timer ticks are still firing.
How / Where can I place a breakpoint to troubleshoot why a form will not receive focus / denies click events / thinks it is being blocked by a modal of some kind?
It is too difficult to create a minimal example because the backgroundWorker and showDialog code all seems to work properly in other locations, but the gist of what is happening looks like:
Application.Run (new FormA)
...
FormA.showDialog(new FormB)
...
FormB.showDialog(new FormC)
...
FormC.timer_tick() { ...still running... }
FormC.onReceive_data() { ...still running... }
FormC.button_click(){
...
showDialog()
...
showDialog()
...
important.showDialog() { backgroundWorker...database stuff }
...
showDialog()
...
}
(known completion : back to FormC event-loop)
It always gets to "known completion" just fine, important.showDialog() seems to work fine, pops up an animating dialog with no buttons, auto closes when backgroundWorker completes, closes itself and moves on to the next dialogs or exits button click fine.
But once back in FormC-Event-loop, the form will not receive any input, as if it is still blocked by some modal somewhere...
If I change to important.show() FormC will not have a problem, but now there is code in the click event running before database activity is finished...
I am more interested in debugging technique in this case as to how I can figure out what windows is doing as I try to click on FormC. What kind of debugging module symbols need to be loaded? Where can I breakpoint to see windows deciding whether a form can receive focus/input?
"something has gone wonky with the re-enabling mechanism" made me go through with a fine tooth comb and check how the dialog is being closed off, and I found the original problem:
FormC starts a backgroundWorker and then waits on important.showDialog()
Inside the RunWorkerCompleted() or a timer_tick : "important" was FormC.BeginInvoke() .closed() and .disposed() . But apparently the .dispose() can (but not always) happen on the wrong thread or at the wrong time and then the parent form can never be enabled again. .close() and nulling the formDialog reference allows the parent to get re-Enabled.
Out of interest, I am still wondering how you would go about debugging such a situation?
I have a forms program that displays two forms. Essentially form1 hides form2, rebuilds it's contents by creating a checkerboard, then shows form2. If I go thru it a step at a time, everything displays fine. I want to run several sequences of hide-rebuild-show with a short pause between each display of form2 so I can verify it is working as expected. If I put a msgbox after each show I see form2 drawn correctly. If I put a 2 second pause (loop doing nothing for 2 seconds) after the show I see the outline of the form but an open space where the checkerboard should be. I think it's some sort of timing issue but don't know how to fix it. What's the correct way to do a short pause?
private void Do1Bot()
{
SetStart();
for (int i = 1; i <= numsess; i++)
{
NextSess();
Do1Sess();
//MessageBox.Show("After do1 sess"); // Checkerboard appears in the middle of the form this way.
//Wait(2); // This way I get the form borders but a blank space in place of a checkerboard.
}
}
private void Wait(int secs)
{
DateTime Tend = DateTime.Now.AddSeconds(secs);
do { }
while (DateTime.Now < Tend);
}
Adding Application.DoEvents() to the wait loop (thanks to Sam Axe) solved the problem.
I have a tricky problem here that I have not been able to solve and neither have the people I asked on msdn forums.
I am using a third part product (signal lab from mitov.com) which is a set of .net components.
I have created a windows form app that works fine if it is run.
I now want to show this form from another form when this other form loads (or shows, or activates...).
I already have examples of this working with another form: Here is the typical code:
I am loading a form (SecondForm) from the main program...
private void SecondForm_Load(object sender, EventArgs e)
{
Form _macros = new Macros(this); //this works perfectly fine
_macros.show(this);
//this is where I have no success
Form _spectrum = new SpectrumScope;
_spectrum.Show();
}
I get various errors from no form displayed and then an exception about not instantiating the _spectrum, to an error about cross threaded operation not being allowed, to a blue screen with a message about clocks not being synchronized between processors.
If I place a button on "Second Form" and add the show form code to the click event, it works fine.
If I try to use form.activated, or form shown instead of form.load there is not difference.
If I add a time to form Shown, which then does a button.performClick, there is no difference.
Obviously the form which contains many components (and many threads behind the scene) does not like the fact that it is not being opened by the user.
I'm fairly new to C# and I'm pretty sure this is threading related.
Thank you for any help.
Try the blow code in your form load method, that should let .Net manage the threading for you.
this.Invoke(new MethodInvoker(() => (new SpectrumScope).Show()));
Well, the problem is fixed. However, I don't really know why the issue exists.
In the spectrum form I reference static variables in the secondform. Now, I use them as follows:
string newFrequency = secondForm.frequency;
This works. However, some of these variables need to have this done:
string newBandWidth = secondForm.bandwidth.substring(2,4);
This is the command that fails. I am told I need the "new" keywork.
I changed my code provide the the string without the need to get the substring and now it all works ok.
Anybody have any ideas?
Pretty new to DevExpress, my company is stuck using 9.3
I've got this very small snippet of code:
wait = new DevExpress.Utils.WaitDialogForm("Please wait...", "Performing SVN check");
wait.Visible = false;
wait.ShowDialog();
ParseSVNResults(CheckSVN());
wait.Close();
My WaitDialog displays, but the code never continues. I put a breakpoint on ParseSVNResults and when I run the code it gets to that line.
It works properly if I just call Show() instead of ShowDialog(), but that gives poor behavior should the user click outside of the Wait form. The application "whites out" like it's stopped responding and the mouse changes into that little rotating circle icon. Also the hour glass that the dialog form shows doesn't rotate. Stupid minor detail, but it looks like the whole application crashed to end users.
ShowDialog, by design, "blocks" the code until you close the dialog. That is the entire purpose.
The reason that Show() is causing everything to white out is that your work is happening in the UI thread. The proper way to handle this would be to move your work (ParseSVNResults) into a background thread, via something like BackgroundWorker or a Task.
I created a very basic console app that executes some code behind the scenes. While it's doing this, it generates a custom message box (it's technically a Windows Form) that just displays one label telling the user to please wait. The issue is that the label NEVER is displayed (it's just a big white box where the label should be). I tried creating a dynamic label and putting it there, but this too does not work.
The form is shown in the following manner:
public void DoSomething()
{
MyForm form = new MyForm();
form.Show();
try {
// Execute other logic
} finally { form.Close(); }
}
I'm guessing it has something to do with calling Show(), but I'm not positive. I put in logging and see that it's going through the constructor, generating the dynamic label (which is added to the form via Controls.Add(myLabel)), but it still does not show any label.
A Form requires the message pump to be started in order to display correctly. This requires calling Application.Run. Unfortunately, this will block the current thread until the "application" is complete, so won't be able to just "drop in" to your code.
That being said, if you're developing an application which requires windows, you should consider making it a true windows application instead of a console application. You could just hide the main form, if required, and that will allow code like yours above to work properly.