I am working in a machine vision project.In my project i am using camera for print inspection.
In my application i am using one picturebox for displaying a image on screen and two buttons.In two buttons one button for live display and another for fullscreen.With the livedisplay button I am displaying image in picturebox in a while loop. in the same time while process in while loop i have to press fullscreen button. but I can't press fullscreen button because while the loop is running it doesn't allow me to push any of the buttons of the form. (The loop is a while) Why is this happening? How can I click this button while the loop is running?
Welcome to the wonderful world of multi-threading. You need to put your while loop on a separate thread, so your UI remains responsive. Threading is a long, deep concept, and there are a million ways to do it.
Probably the path is least resistance is to use the BackgroundWorker threading model. See here for more details.
One solution can be rather than running a while loop; use a timer with some interval and on timer tick update the image in picture box. You can start the timer when user clicks on Liveupdate button. You can keep the interval very low(e.g. 100ms) so that your updates will give feeling of being LIVE. This will give some interval in between two updates when application can take input for other user action like other button click.
Related
I am developing an app in uwp where I dont want to exit the application on back button click(on mobile).Instead of exiting I want to run it in background(it also uses a timer which triggers every 5 second).
Could anybody please help me on this.
Thanks..
A few things to mention:
A UWP app does not exit on pressing back button. It generally goes into a suspended state. It starts running in background only if you have registered a background task.
A background task can be triggered using a time trigger. But the minimum time period between 2 triggers is 15 minutes. So, you might want to look into some other to handle this.
You might want to look at these if you want to understand more clearly
https://blogs.windows.com/buildingapps/2016/04/28/the-lifecycle-of-a-uwp-app/
https://blogs.windows.com/buildingapps/2016/06/07/background-activity-with-the-single-process-model/
[Mouse cursor over window]: When I type in textboxes, on a .NET C# 4.0 window, the mouse cursor disappears and this is strange by itself.
[Mouse cursor outside window]: When I type in textboxes and press ENTER key to do some stuff in the UI thread, and then while doing that stuff, I move the mouse cursor over the window, the mouse disappears.
What can I do to keep the mouse always visible?
When typing in a text box (in any application) Windows will automatically hide your cursor. Some UI person will probably say that it's to prevent distractions, this is just my guess. If you move your mouse again, it will reappear.
The reason that your cursor is staying invisible while doing work in the UI thread is just that: Your application is busy doing work on the UI thread. Because your operation is happening there Windows is not able to redraw the area of the screen where your application is. That's why the mouse "disappears" again.
The two issues while manifesting similarly are different.
If you know that you need to do a lot of work, but it doesn't interact with the User Interface at all, you should kick off that work in a separate thread, so that your application continues to feel responsive to your user.
If you eventually need to do cause something to happen to the UI from another thread, you'll need to check out the Control.Invoke method.
Hello I want to press a button with my app. So I use SendKeys class
SendKeys.SendWait("{RIGHT}");
Problem is that I need to wait 3-4 seconds after this line code for reaction from system. How can I speed it up or how can I delete this delay ?
// update 1
I've also tried
SendKeys.SendWait("{RIGHT}");
SendKeys.Flush();
BUt id didn't help
// update 2
I want my app that works in background to press a button programaticly in the actual active state of the user. So if he is in excel i want the right arrow to move the active cell, if he is in the game i want to turn right etc. SendWait does the thing I want but with some delay that I don't want.
Second important thing that this is not a virus or worm or anything like that. First of all as you can see I'm too stupid for that and secondly I'm playing with my KInect so this is some kind of interaction beetwen user and computer. Thats why it works in background and thats why I need to send it to the active app of the user
SendKeys is a nice little feature for Windows Form applications. Based on your tag it appears that you're using Windows Presentation Foundation, which will not support SendKeys.Send()
https://stackoverflow.com/a/1646568/340574
Take a look at the link above to use KeyEventArgs. I've read that you could also add a reference to System.Windows.Forms.dll through Visual Studio to use SendKeys, but I have not tried it myself.
I have a C# application that runs on a computer connected to a large display in our cafeteria. The application pulls all the PowerPoint files out of a folder and runs each one as a slide show continuously. Everything was working fine until someone decided to insert a movie clip onto a slide. The problem is that the movie never starts. If open the presentation in PowerPoint and run the show it works, and if I right click on the presentation and click 'show' it works. Here is the code I am using to open the presentation and start the slideshow.
pres = app.Presentations.Open(pptPath, MsoTriState.msoTrue, MsoTriState.msoTrue, MMsoTriState.msoFals);
pres.SlideShowSettings.Run();
Is there something else I need to set to get the Run() method to also start movies?
Edit: The presentation in question only had one slide in it which contained the movie. If I added another slide to it, it worked fine. Also tried adding a slide before and had the same problem, so apparently the problem only exists for the last slide in the presentation.
The main issue here is that PowerPoint animations (video, audio, custom motion paths, etc.) will only play when the SlideShowWindow has the focus. What this means is that when you're running your app and launching PPT, your app still maintains the focus and hence animations don't run (that doesn't stop you from manually manipulating your running deck though).
There are a couple of ways around this:
You can call the API SetWindow to
bring your SlideShowWindow to the
front. Not a great way to do it in
my opinion.
The very easiest way is just to save
your .ppt/.pptx to a .pps/.ppsx
(PowerPoint Show). With that, you
can use your same code to run it and
it will launch and take the focus
automatically (and your animations [video, et al) will run as you've intended).
Found the problem. I had a thread.sleep statement in the presentation's app_SlideShowNextSlide event handler that handled the end of one slideshow and starting the next. I wasn't thinking at the time and this code was running in the same thread at the slideshow itself. I created a timer object instead and moved the necessary code into the timer's elapsed event handler.
how do i calculate the loading percentage of my C# application. i want to show a splash screen with a progress bar showing percentage of application loaded.
Is there any standard method\library for that or i will have to just update the progress bar value at different points in my form load code.
Or can any gimme a tutorial on application preloaders
The first time user starts your application, assume it will take 10 seconds and show progressbar counting down those 10 seconds. Once the application is loaded, save somewhere on user's computer actual time it took to load your application. Next time user loads your application, use saved time instead of your original 10 seconds.
This is simple and obvious concept. User doesn't care what parts of the application are loading, he cares how long it's going to take and he wants to see countdown.
Probably the easiest way to do this is to create an instance of your splash form at the beginning of your startup form's Load event. In the splash form, expose its ProgressBar as a public property. After creating the splash form, set its ProgressBar's Maximum property to the number of discrete steps that you can identify in the Load event code, then show it by calling its .Show() method (not .ShowDialog(), of course).
As each step in the Load event completes, you just increment the public ProgressBar's Value property. When all steps have completed, close the splash form and dispose it.
This may or may not work properly, because if your startup form contains a large number of controls, then a good percentage of the total loadup time will actually be spent in the form's constructor, which will be called before the Load event. It might be best to move all of your initialization code into the constructor, and create and Show the splash screen from there.
Well, in any case you need a fairly accurate guess at how long your individual steps take. Only then can you give an actually meaningful progress bar. You can approximate it by dividing your loading process into several steps you assume to be roughly equal in time and calculate progress as you finish those steps.
An alternative would be not to show a progress bar but rather a series of loading steps, represented either by text or graphically. I think KDE does this on startup. That way you show progress but avoid the user's expectations towards a progress bar (which works best if the progress bar is either linearly progressing or accelerating. If it frequently stops and jumps it just creates the impression of a very slow process).
Another option would be to eliminate the splash screen entirely by trying to make program startup fast and loading what you need at runtime. This may or may not be an option for you or your program but it can show pretty significant improvements in startup time and overall impression of program speed.
First of all the Splash screen is shown to give user an illusion that program has started and they will be handled control at any moment.
Secondly if you want to show the progress bar then you need to accurately calculate the number of tasks you perform. Then show the label loading xxxxxx....... and increment progress bar after completion of every item.
As for the question of optimizing starting up time it mainly depends upon the function of your application.
Suppose you app is a PIM then you may load the events and tasks for today and show it to the user quickly and then start loading other data.
I once had an application where I had to show the object hierarchy using Treeview each node could have unlimited number of items. I loaded the top level objects and displayed then in the tree view and put marker (actually I put * in tag of the node, which I learned from some .net book or article I had read long ago but remembered) when use clicked on the node I loaded the immediate children.
A Pretty Good Splash Screen or Splash Screen