For couple of hobby projects of mine, I've been performing form transitions (fade-in/out, slide-left/right) using timer control, and I know its not the right way to do it. Using timer has its own disadvantages as it is a CPU hog if logic is complex and also, transitions are not smooth. So, I'm wondering how can I perform form transitions without using any timers and just by using native Windows API or any third-party library. I came across with FlowFX but found that it is limited only to .NET Compact framework.
Thanks...
We don't know what your timer handler is doing without a code sample, but using a timer to do animations is an acceptable method.
Here is another SO question and answer that might show you a better way of coding your timer handler.
The "not smooth" part could perhaps be overcome using double-buffering.
Related
I need to play several sounds, and if one sound is already playing, the subsequent sounds will be queued.
I'm using MCI API calls.
Until now, I'm using this sound player as a COM control with InterOp.
However, the COM control causes some COM Release errors, so I would like to solve it differently.
I would like to know if I should solve this by a usual NET class in my form using a background task so that I'm completely indepenent on how heavy the load of my application is so that finished sounds can immediately trigger playing the next sound without any delay, or if that would be an overkill, and background tasks should only be used on long, blocking operations.
My sound player basically only uses a timer to check with an API call if the MCI has stopped playing and then starts the next sound.
Also, it provides events when a sound was started, stopped or errored-out.
Or if I should encapsulate the player in a separate NET project and reference it? Then I would also be independent on the workload of the main application.
Seamless playing of the sound queue would be essential to me.
I've an application witch update execute commands on a database. I've a function witch execute that commands and in the in this function I display some messages to the user.
My problem is that the texts written into the textEdit are displayed at the end of the function work.
I've tried to use QThread but it does'nt resolve the problem
this->moveToThread(&threadText);
connect(&threadText, SIGNAL(started()), this, SLOT(writeTexte()));
threadText.start();
Does anyone have an idea how to proceed to write into textEdit and not block the UI ?
In Qt you never need threads in standard UI applications! That is because Qt uses something called event loops that process events smoothly without ever blocking. If you experience blocking, that is a sign that you have a bug somewhere in your code. For any beginner there are some pitfalls. The official documentation on the subject is quite good.
It is hard to tell what your exact bug is because there is littel code to look at. I suggest you post more of your code, especially the naive approach that did not work before you added threads to the mix.
On a side note, using threads in Qt is of course possible and has it's usages, however it can be un-intuitive. I have found this article to be a really good starting point to understand how threads is used best in Qt.
I am in need of a solution, and I am not quite sure I have enough knowledge to properly ask the question, so please bear with me. I am working with a CAD application with it's own API which supports the .NET Framework 4.5. I wanted to develop some customized functionality for the application using VB.NET, but because of work restrictions I am not allowed to install custom programs or run custom executables. I am however allowed to utilize the CAD applications scripting environment (which also supports the .NET Framework). I am limited in what I can achieve with scripting because as far I know I can't listen for an event in a script, because the scripts run time ends so quickly. Is there a way to extend the run time of a script until certain events occur? If anybody is curious, the CAD application I am using is called Siemens NX. Any Ideas?
I do not know how far this answer help you.
When you do not have events to listen, try to depend on return variables and using assert statements (or at least if statements).
I mean, if something happens then only go to next, which is a very traditional way.
Also, if you want to prolong the run time of script you can use some thing like "sleep" or "delay" statements (may be milli seconds as input).
I mean if some thing is happening (control by a variable), "sleep" till that action is complete.
Or check for the action complete status in a infinite while loop and exit, when it is done.
In simple terms, traditional way of doing things helps in your situation.
Firstly, I've never used threads, but have found lots of examples on the internet about their use but nothing that obviously answers my question.
I have a class that loads and manipulates a file(s). It is fairly CPU intensive so I intend to put it in its own thread so that the GUI remains responsive. However, I would also like to use a progress bar to indicate the current status of the file operations.
The question is, what is the best way of approaching this, i.e. How do I get my file class to tell the app where it's up to? Do I have to add thread specific code to my class? Or is there an interface I can implement? Or, am I approaching this all wrong. Additionally (sorry, another stupid question) I assume I need an indicator in my file class to tell the thread when it's finished?
I'm using VS2010 and intend to build the app with WPF (if that's relevant)
Thanks for any advice,
Bob
Since you are intending to use WPF, use a Dispatcher:
Build More Responsive Apps With The Dispatcher
(Otherwise, for Winforms use a BackgroundWorker)
I have a college assignment due quite soon, and I need to be able to call a C++ dll that takes a long time (possibly infinte, it relies on user input)to execute. Im calling this through VB. My VB GUI freezes up when this happens, and I would like to keep the GUI responsive, so that the user can stop this possibly infinte loop.
Can anyone suggest the best/fastest way of doing this?
A bit of background, the C++ is trying to keep score on a snooker table using a webcam, and while the VB scoreboard updates easily, I would like to script it so that the analysis is almost continuous, while still allowing the user to interact. Currently the project requires the user to press a button to start the shot analysis, but it would be preferable if the program scripted itself. I have only realised this problem now and the deadline is very soon.
Update: Our lecturer suggested an option to solve the problem, but it would appear that most options here and the one he suggested will not work for us as the processing time required for the webcam image capture is too great to handle due to hardware constraints. Thanks for taking the time to help, it was much appreciated!
The best way to handle threading in VB.NET is via the System.Threading namespace.
You might also look into Application.DoEvents()
Try the system.Threading as Mark said, also try looking at Background Worker Process which is a bit simpler in VB.NET. Readup here
I would definitely use the Background Worker process. You can drag it onto your form and use the DoWork sub routine to actually do the work that is freezing your GUI thread. You can also use the ReportProgress event to actually provide progress back to your form.
As for your question regarding two separate threads, If both steps take a long time to complete I would run them in the same thread one after the other.
The one thing that could bite you with using the thread is cross-threading. In the context of your problem this means not having your second thread update form controls.
A really good resource for how to implement this code along with dealing with cross-threading is this PDF.
I also should point out that if you are using .net 1.0/1.1 you can still do the multi-threading, but don't have the luxary of having a background worker control. You'd just have to create a new thread from the System.Threading Namespace.
Just as an alternative, you could have your C++ actually processing in the background all the time. When called from VB, it would just be retrieving data from it or sending it a command (start, quit, ???) all of which would return instantly.
This could also give you more reliability since C++ would never miss video frames while VB was collecting the garbage or doing the dishes or whatever VB does in the background--C++ is going to let you be closer to a real time system.
RE: the comment about how.
What I'd probably do is have my VB programs send "Messages" to the C++ (As I said). A message is just a way to think of a function/method call--but generally they return quickly.
The "Start" message would tell the C++ code to start it's thread running and return. This is a Linux C++ thread howto, I'm not sure if you need to do something different in windows (I'd hope not, but I haven't used C++ as my main dev. language in decades).
If that doesn't work, just google "C++ Threads"
Sending a "Stop" message would stop the thread (and probably free resources).
A "Get Data" call would go to the location that the C++ thread used to store data, grab it and return.
Sorry to be so general, I'm pretty heavily Java these days.
I'm surprised nobody has suggested using a BackgroundWorker yet.