backgroundworker in infinite loop - doevents

Except doevent() is another way that, in this infinite loop run another control in form.
I wanted to do it with backgroundworker, but I failed.
private void button1_Click(object sender, EventArgs e)
{
while (true)
{
Application.DoEvents(); //how i can use the backgrondworker in this place
}
}

The question and sample are confusing to me but what I think you are asking is how to use the BackgroundWorker class.
The Documentation for this class is pretty helpful and has sample code towards the bottom.

Related

Eventhandlers between different forms (parent/child)

Im quite new with c++ and so far im having a little trouble understanding the basics. i got 2 forms right now.
parent.h
#include "child.h"
public ref class parent : public System::Windows::Forms::Form {
child^ v_child = gcnew child;
void InitializeComponent(void){
v_child->Load += gcnew System::EventHandler(v_child, &child::child_Load);
}
private: System::Void child_Load(System::Object^ sender, System::EventArgs^ e) {
MessageBox::Show("Howdy");
}
}
i basically want the parent to do something when the child has an event, in this case, just a Load. it compiles and gives no warning/error, child execute the event, but it never triggers on the parent.
wanted to do this to be able to interact between parent and child, which so far, im having so much trouble doing so.
To be clear, do you want parent to react to a "Load" event on the child?
If so, then you're linking the event incorrectly. Your code:
v_child->Load += gcnew System::EventHandler(v_child, &child::child_Load);
Links the Load event handler to the v_child not to parent. Try this instead:
v_child->Load += gcnew System::EventHandler(this, &parent::child_Load);

StartCoroutine get error NullReferenceException

I have two cs files, Main.cs and Menu.cs. On OnGUI event which is in Main.cs file I call method from Menu.cs.
private void OnGUI()
{
Menu menu=new Menu();
menu.Create_Menu();
}
And in Menu.cs.
public void Create_Menu ()
{
StartCoroutine(LoadCar());
}
private IEnumerator LoadCar()
{
//Load Object
Download download;
download=new Download();
GameObject go = null;
yield return StartCoroutine(LoadAsset("http://aleko-pc/3dobjects?key=1017&objecttype=1","car13",(x)=>{go = x;}));
}
I get error NullReferenceException
UnityEngine.MonoBehaviour.StartCoroutine (IEnumerator routine)
If I copy private IEnumerator LoadCar() method in Main.cs class, and call from OnGUI it works.
Maybe I do not understant working area of Coroutines, Can any body help me?
First of all the OnGUI method is called every frame and I don't think you want to download the assets every frame.
Second, you need to make sure Menu is derived from MonoBehviour and added to the view hierarchy.
A better approach would be to add Menu as a component to a GameObject (maybe the same that has the Main script attached) and call Create_Menu on the Start method of Menu.

Android Frame animation does not proceed more than one image

I have created a folder called anim inside res folder. I have put 9 consequtive images in a folder called drawable inside res folder. Now I have created this:
public class AndroidAnimationActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_screen);
ImageView myAnimation = (ImageView)findViewById(R.id.myanimation);
final AnimationDrawable myAnimationDrawable= (AnimationDrawable)myAnimation.getDrawable();
myAnimation.post(new Runnable(){
public void run() {
myAnimationDrawable.start();
}
});
}
}
As you see I am trying to display this animation on a page called about_screen. It only shows the first frame and the rest of the frames are not shown (as animation). I have seen several people having similar problem like me but not exactly the same. I hope someone can help me with this. Please be specific. I am a new android learner. Thanks
Even I faced this problem, and the solution is simple.
The problem is, you are calling myAnimationDrawable.start() inside the onCreate() function.
You have two possible alternatives...
First one, make the animation interactive, so that you can call myAnimationDrawable.start()
inside some onClick() function.
Second option is to call myAnimationDrawable.start() inside View.OnFocusChangeListener(). In this case you don't have to make it interactive.

Events in Windows

How can i capture all user raised events in my application, is there any specific event which is parrent for all of user based(raised) events ?
eg :
mouse click,
key press,
etc.,
these all events are raised by user can i able to capture it under one method???
In one single method: yes.
You have to implement the DefWindowProc function, which handles all events and messages. Unfortunately, not just user generated events but all. But you should be able to filter those out easily.
Use the SetWindowsHookEx API to set up a thread-local WH_CALLWNDPROC hook. See the MSDN documentation for full details.
That will call a single function in your application for every message you receive from Windows.
If you're using Windows forms .NET, add the following to your main application form:
protected override void OnControlAdded(ControlEventArgs e)
{
e.Control.Click += new EventHandler(Control_Click);
e.Control.KeyDown += new KeyEventHandler(Control_KeyDown);
base.OnControlAdded(e);
}
void Control_KeyDown(object sender, KeyEventArgs e)
{
// Hande all keydown events, sender is the control
Debug.WriteLine( sender.ToString() + " - KeyDown");
}
void Control_Click(object sender, EventArgs e)
{
// Hande all click events, sender is the control
Debug.WriteLine(sender.ToString() + " - Click");
}
protected override void OnControlRemoved(ControlEventArgs e)
{
e.Control.KeyDown -= Control_KeyDown;
e.Control.Click -= Control_Click;
base.OnControlRemoved(e);
}
Just add any extra events you require (such as KeyPress, MouseEnter, MouseDown etc) in a similar manner. This is a bit cleaner and simpler then delving into the Windows API.

Catching the scrolling event in gtk#

Which event from which widget should I catch when I need to run some code when ScrolledWindow is scrolled?
Ths widgets tree I am using is:
(my widget : Gtk.Container) > Viewport > ScrolledWindow
I tried many combinations of ScrollEvent, ScrollChild, etc. event handlers connected to all of them, but the only one that runs anything is an event from Viewport that about SetScrollAdjutstments being changed to (x=0,y=0) when the application starts.
You should attach to the GtkAdjustment living in the relevant scrollbar, and react to its "changed" event. Since Scrollbars are Ranges, you use the gtk_range_get_adjustment() call to do this.
unwind's answer was correct.
Just posting my code in case someone needs a full solution:
// in the xxx : Gtk.Container class:
protected override void OnParentSet(Widget previous_parent) {
Parent.ParentSet += HandleParentParentSet;
}
void HandleParentParentSet(object o, ParentSetArgs args) {
ScrolledWindow swn = (o as Widget).Parent as ScrolledWindow;
swn.Vadjustment.ValueChanged += HandleScrollChanged;
}
void HandleScrollChanged(object sender, EventArgs e) {
// vertical value changed
}
If you need to change the parent of any of those widgets, or may need to change the types and change the hardcoded types and handle disconnecting from the previous parent.