|
Right, I understand the idea of the delegate and I know how to call one from a backgroundworker or from a STA thread.
My problem is that the code that I'm using (third-party) is running under an MTA (multiple apartment) thread.
I cannot seem to get the same delegates that work just fine from a backgroundworker to work under the MTA thread.
It's my impression that the MTA threading is a different animal entirely...that the GUI is based on calls from STA threads.
Am I wrong about that?
|
|
|
|
|
cstrader232 wrote: It's my impression that the MTA threading is a different animal entirely...that the GUI is based on calls from STA threads.
Am I wrong about that?
Nope. You're not. I'm just too tired and missed that part of your post.
Hmmm...
|
|
|
|
|
Wow, have I really stumped DK? First time on that for me! Makes me wonder whether this is even possible.
|
|
|
|
|
Stumped?? Hardly. I just need to do the research and come up with a testable solution. Time is a bit short right now, so this takes a while.
|
|
|
|
|
Well, it does work and without anything "off the wall". This is the test case I put together under the .NET Framework 2.0. The only controls are a Form, TextBox, and Button.
Imports System.Threading
Public Class Form1
Private Delegate Sub UpdateTextBoxDelegate(ByVal Message As String)
Private Sub UpdateTextBox(ByVal Message As String)
TextBox1.AppendText(message & Environment.NewLine)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles Button1.Click
For x As Integer = 1 To 20
Dim t As New Thread(AddressOf GenerateData)
t.SetApartmentState(ApartmentState.MTA)
t.Start()
Next
End Sub
Private Sub GenerateData()
Dim callback As New UpdateTextBoxDelegate(AddressOf UpdateTextBox)
For x As Integer = 1 To 10
TextBox1.Invoke(callback, New Object() { _
String.Format("Thread Id: {0} Apartment: {1} Message: {2}", _
Thread.CurrentThread.ManagedThreadId, _
Thread.CurrentThread.GetApartmentState().ToString(), _
x)})
Next
End Sub
End Class
Sorry, I just went back and found out you're using a third party component. The short version of apartments is COM components written in STA mode can only have one thread call their methods at any one time, the thread that created the component. In MTA (sometimes called "free threading", multiple calls to the component's methods from any thread(s) are possible with complete safety.
Since most of Windows Forms and the controls it supplies wrap the existing COM controls, most of which are written in STA mode, the default apartment mode for a Windows Forms app is STA. It's possible to change this, but not a good idea because the COM controls backing Windows Forms requires an STA environment to run.
Calling a method of a control in STA can be done from any apartment mode, so long as the call is marshaled to the thread that created the control. It matters more about the apartment your code is calling, than the apartment the call is comming from. I'd be willing to bet that there's something in this third party component that is not marshalling the call back to STA correctly.
|
|
|
|
|
OK, thanks... I think you are on to something there. The 3rd party code is not allowing me to make my callback properly. I'll try to keep checking into this. Thank you so very much for your time....really appreciated.
|
|
|
|
|
Thank You, that is exactly what I need to be using.
|
|
|
|
|
I dont know what is the use of performance counter and how to use it... im just wondering if i could use it on my project...tnx
Sunshine
|
|
|
|
|
|
Click on the Start button, then on Run. Type PERFMON.MSC and hit enter. This is the Performance Monitor. You can montior all kinds of system information such a network activity, disk access, memory usage, ...
The performance counter classes let your code create and expose custom counters so you can monitor components work using PERFMON or some other performance monitoring tool.
|
|
|
|
|
Have you looked around at the PerformanceCounter class?
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
I have an application in Vb.net. There is a crystalreport that displays records from an access Database.But i want to filter records that report displays.Each records has 6 fields and one of this is LisTR.
I have a function VerifyS(...) as boolean , this function get as argument the value of this field and return true if the record that have this filed should display in the report or no.
But i have problem using this function.
I use : CrystalReportViewers1.SelectionFormula=("VerifyS{Table1.LisTr}=True")
But i get an error
So , How to use a function inside SelectionFormula?
Thank You !
|
|
|
|
|
If this VerifyS function is defined in your VB.NET code, you can NOT use it in the SelectionFormula filter. Last I knew, CrystalReports cannot call back into your code to call functions.
The way around this would be to add a field to your table that your code can modify based upon your rules, then you can use that field in the SelectionFormula to filter the records.
|
|
|
|
|
Thank You.
Ok , i change my code and now i want to display in My crystal report only those records that have the maximum value in the filed LisTR. Can i use the function Max or something else to do this. ( so is possible to use in SelectionFormula a standart function of vb.net ?)
Thank You
|
|
|
|
|
mysybet123 wrote: so is possible to use in SelectionFormula a standart function of vb.net
Didn't I just get done telling, "No, it's not possible."??
Stop thinking in terms of VB code in the SelectionFormula and start thinking in terms of either SQL or CrystalReports syntax.
|
|
|
|
|
Hi guys,
I need to create a matrix (array) of buttons at runtime, and i need to associate to every button a couple of events like "MouseDown" and so on.
I explain:
- I get a number from outside (a parameter) that tells me how many buttons I must create in my form, obviously at runtime since I don't know the number before;
- these buttons will be like puzzle items, so for each one I must associate a "mousedown" event and others to let the user move them in the form (actually, from a Panel1 to a Panel2 in the same form);
I tried to create at runtime a matrix of buttons, but this object cannot be associate with events... the same thing happens with a "List" objbect...
anyone has an idea on how to proceed?
thank you
-- modified at 8:16 Wednesday 3rd October, 2007
|
|
|
|
|
diebugger wrote: but this object cannot be associate with events...
Yes it can. You just have to "wire up" the events yourself using AddHandler and RemoveHandler[^].
|
|
|
|
|
Thank you for the quick reply!
I can do that within a class or a structure, but not within a matrix of some kind of object/class. That's the problem, an event, whatever it is, cannot be associated to a matrix (1-dimension in my case): it's what I read from MSDN and compiler errors until now. Anyway, I continue searching in the direction you gave me.
One more hint:
think about coding a windows application to play puzzle, this is a form with two panels and the programs read from a file the numbers of puzzle's items. Then it loads items into Panel1 and you (user) must drag&drop items into Panel2.
This all works fine if I set as costant the number of items (like =10) and in this case I don't need to create an array at runtime but I create 10 buttons on my form at design time. How can I do if I don't know the items number before? Hope you got it.
Thank you again.
---
die
|
|
|
|
|
diebugger wrote: I can do that within a class or a structure, but not within a matrix of some kind of object/class.
The button events still fire, no matter what collection they are in. You can still wire up the events to a handler in the form code.
diebugger wrote: but not within a matrix of some kind of object/class.
Matrix has no meaning here. Are you saying that you want to wire up the events to a method in a custom class??
diebugger wrote: think about coding a windows application to play puzzle, this is a form with two panels and the programs read from a file the numbers of puzzle's items. Then it loads items into Panel1 and you (user) must drag&drop items into Panel2.
I wouldn't be using buttons, or any other controls, to represent the pieces, that's for sure.
|
|
|
|
|
you should add a handler to each of the Controls (not to the array).
this takes a single line of code inside the loop that creates the Controls!
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
That was. Thank you, I'm just at the beginning of this event driven programming
---
die
|
|
|
|
|
As far as i can see, what you want to do at this stage is to create a Matrix(Array) of button, and when you get the number from outside you need to load those buttons.
So for that you can write for loop and declare global variable which will store the X number you get from out side and put the code of loading button.
This is how you can do it.
1. Create one button and put it's Index to 0
2. Start your for loop from 1
For i=1 to x<br />
load button <br />
button index = i 'this will get you the name of button e.g. button1(1)<br />
Next i
3. And now you can put you functions init.
Hope this helps you. If you have any questions feel free to ask.
Parth Patel
|
|
|
|
|
Hey all!
I'm having a situation here whereby I would like to join two bitmaps and make it as one.
How can I do that?
I've already got two bitmaps, both having their own set of drawings; Lets call them Bitmap1 and Bitmap2......now I would want to union them together so that the final result would be a bitmap that will contain everything from Bitmap1 and then just after Bitmap1, Bitmap2 will be appended to it. So im not trying to overlap them with one another, i just want bitmap2 to appear right after bitmap1.
Thanks in advance!
Regards,
jensen
|
|
|
|
|
Try creating a new Graphic and using a For loop over all the pixels of an image using the GetPixel() method. So if image 1 is 300x300 and image 2 is 300x300 then create a new graphic with size 600x300 and place the pixels in the new graphic by using SetPixel()
Good Luck!
--Zaegra--
|
|
|
|
|
Zaegra is partially correct.
You create a new Bitmap object the size of the two bitmaps you want combined. So, if you want Bitmap2 to show up under Bitmap1, create a new Bitmap object the height of Bitmap1 + the Height of Bitmap2 and the width of the widest of your two bitmaps. Then you create a Graphics object from this new Bitmap object and use it to "DrawImage" the other two bitmaps onto your new Bitmap in the appropriate positions.
|
|
|
|