I'm new in C#, and I'm working on some application to do direct audio recording and realtime plotting on screen. Now I'm having a lot of trouble to update the screen yet, it has been taking me almost a week now and been searching everything without result. I hope somebody could help me here..
The detailed problem is as followed:
I have a form and within this form I declared a callback function which is (and has to be) declared as a static to avoid certain "CallbackOnCollectedDelegate" errors. This is handled by initialising the callback as a new type (and this certain type expects a static).
The audio (callback) runs fine, if it's declared as a static though.
Now I receive constant new information within this callback routine and I'd like to send it to the form (gui).
I understand I should use begininvoke to make sure there are no crossthreading problems. Next I try to update the gui from the function which I hand to the begininvoke method.
Yet now the compiler tells me I have to give a static function to the begininvoke method (probably because this begininvoke is within the static callback (which has to be static)).
Now that would be ok, yet if I make the begininvoke-function also a static function, I cannot reach the gui anymore (the "this" keyword is not allowed anymore).
Does this mean it's impossible to reach the GUI from a static function?
Or do I have to make the form also a static? (I read that this is not possible).
Does anyone know how I could tacle this problem? I would be very grateful!
Here's some of the code (without unrelevant stuff):
Expand|Select|Wrap|Line Numbers
- namespace APItest
- {
- public partial class Form1 : Form
- {
- delegate void UpdateProgressDelegate();
- unsafe public static void* stream;
- unsafe public static PA19.PaStreamCallback callback = new PA19.PaStreamCallback(PACallback);
- //-----------------------------------------------------------------------------------------------------------------------------
- unsafe public static int PACallback(bla...)
- {
- MethodInvoker mi = new MethodInvoker(this.UpdateProgress);
- this.BeginInvoke(mi);
- return 0;
- }
- //-----------------------------------------------------------------------------------------------------------------------------
- void static UpdateProgress()//int time, ref int refParam
- {
- this.label1.Text = Convert.ToString(count++);
- }
- //-----------------------------------------------------------------------------------------------------------------------------
- unsafe private void cmdStart_Click(object sender, EventArgs e)
- {
- error = PA19.PA_OpenDefaultStream(callback);
- error = PA19.PA_StartStream(stream);
- }
- }
- }
-Michiel