|
Your assumptions are wrong. The compiler will turn this:
System.Diagnostics.Debugger.Log(0,"", "Current thread is: " + Threading.CurrentThread.GetHashCode());
into this:
int tempInt = Threading.CurrentThread.GetHashCode();
string tempStr = string.Concat("Current thread is: ", tempInt.ToString());
System.Diagnostics.Debugger.Log(0,"", tempStr);
JoeRip wrote: But now it occurs to me that I have no idea if my method is guaranteed to be executing on the same thread all the way through. Is there some chance that after AnotherMethodWhereWorkIsDone() executes, my handler will be running on a different thread than when I shapshotted it above AnotherMethodWhereWorkIsDone()?
Reply·Email·View Thread·PermaLink·Bookmark
No, that is not possible with plain old methods. (It is possible with yield return iterator methods, but that's another story.)
|
|
|
|
|
Thanks, the debugger.log answer does make sense.
For the other part: so my method is guaranteed to remain on the same thread from beginning to end of execution? Even if I called a method from inside it asynchronously (using delegate.BeginInvoke on its delegate)?
That makes me happy.
|
|
|
|
|
how can i play rmvb videos in panel control using c#.net?
i searched for help but couldn't find something.
thanks in advance.
|
|
|
|
|
I think I read somewhere that you can do this with DirectShow..I tried searching for my source but couldn't come up with it.
|
|
|
|
|
thanks swelborn but all i can do with DirectShow just play rm files (sound files) not rmvb files
|
|
|
|
|
I created an application that logs events inside a text file now. The event information looks like this:
This process works like it should but when opening the log file it looks pretty rough and the format of it could be done alot better.
What I proposed was to have it inputted into maybe an xml file with the parent Node being the Event Name and each time this event fires the application will search the xml to see if this Parent Node exists, if it does it creates a child node below that with its value. If it is not in there it creates the Parent Node and creates the child under it with the value.
When I was thinking about doing this I wasn't sure if this solution would be fast enough to handle the event calls. Sometimes the events can be fired rather quickly and I'm afraid there might be some locking involved when writing to the xml file. To solve this I was going to create another class that will act like a buffer between the xml calls and the event calls, kinda like an MSMQ type class.
I know I could get away with doing something like this using mysql or msde or even SQL it'self..the only problem with this is that this is a Packaged Product and needs to be developed as if the client machine does not have SQL or IIS or anything like this installed. The only requirement would be .Net 2.0 - I dont want to force the purchaser to also have these items already.
So basically what I am asking is if anyone here has any idea's how I can have a async, fast read/write option for my logging? Can I get away with using an XML file as my database?
Thanks.
|
|
|
|
|
Swelborn wrote: how I can have a async, fast read/write option for my logging?
Use Log4net[^]
|
|
|
|
|
I have a button that when clicked opens another form. I want it to check and see if the form is already open, and if it is maximize it/bring it to the front. Is this possible?
|
|
|
|
|
Hi !
Are you hiding or closing the form?
here is a method if your are closing the form:
public ParentForm : Form
{
ChildForm frm ; // I assume that your form is a member of the parent form
public ParentForm()
{
// Components
}
public DisplayAChildForm()
{
if (frm == null)
{
frm = new ChildForm();
frm.OnFormClosed += new EventHandler (frmClosed_evnt);
fmr.Show(); // you can use ShowDialog method also
}
}
private frmClosed_evnt(object sender, EventArgs e)
{
frm.OnFormClosed -= new EventHandler (frmClosed_event);
frm = null;
}
}
that's it
|
|
|
|
|
Hi,
In this way you either create or show the form without using events.
On click the ShowChild method is called.
Test for null or disposed and show it if this is the case.
If the form is ok we test if it is minimized then we restore it and then bring it to the front.
Note that Show brings the form to the front only on the first call.
Note - DO NOT CALL ShowDialog - it does not work if the form has been shown before Your application will crash with an InvalidOperationException
public partial class Form1 : Form
{
private Form childForm;
public Form1()
{
InitializeComponent();
}
private void ShowChild()
{
if (childForm == null || childForm.IsDisposed)
{
childForm = new Form2();
childForm.Show();
}
else
{
if (childForm.WindowState == FormWindowState.Minimized)
{
childForm.WindowState = FormWindowState.Normal;
}
childForm.BringToFront();
}
}
private void buttonShow_Click(object sender, EventArgs e)
{
ShowChild();
}
}
Natza Mitzi
|
|
|
|
|
Hi All,
I'm having real troubles with this. Say I've got two classes BaseClass and DerivedClass : BaseClass . How can I cast an instance of BaseClass and convert it into a type of DerivedClass . All I've done in DerivedClass is add two new properties, nothing fancy.
I've tried various methods:
BaseClass baseClass = new DerivedClass();
DerivedClass derivedClass = baseClass as DerivedClass;
DerivedClass derivedClass = (DerivedClass)baseClass;
The C# 3.0 in a Nutshell book uses this illustration which is also failing ...
DerivedClass derivedClass = new DerivedClass();
BaseClass baseClass = derivedClass;
I was under the impression that a Cast was 'workable' and legal provided there was no dataloss int to long for example. Since DerivedClass contains all of the BaseClass properties I was (obviously incorrectly) assuming that this would be an allowable cast. Is there a workaround that doesn't involve mapping each source property to the target type property?
Jammer
if(glass == Glass.Empty){GoToBarAndOrderMoreBeer();}
else {Drink();}
My Blog | Article(s)
|
|
|
|
|
Here's a sample to play around with. The derivation works fine with this.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestDerivation
{
class Program
{
static void Main(string[] args)
{
List<BaseClass> list = new List<BaseClass>();
list.Add(new BaseClass { Id = 1 });
list.Add(new Derived { Id = 2, Name = "Jammer" });
foreach (BaseClass item in list)
{
if (item is Derived)
{
Derived derived = item as Derived;
Console.WriteLine("{0} {1}", derived.Id, derived.Name);
}
else
{
Console.WriteLine("{0}", item.Id);
}
}
Console.Read();
}
}
public class BaseClass
{
public int Id { get; set; }
}
public class Derived : BaseClass
{
public string Name { get; set; }
}
}
|
|
|
|
|
Hi,
casting from derived class to base class is acceptable but not vice versa if the base class doesn't have all of the functionality that is defined in derived class (which is the usual situation). Consider following
class BaseClass {
public int value1;
}
class DerivedClass : BaseClass {
public int value2;
}
static void Main() {
DerivedClass dc = new DerivedClass();
BaseClass bc = dc;
BaseClass bc2 = new BaseClass();
DerivedClass dc2 = (DerivedClass)bc2;
}
Based on this your second example should be ok.
Mika
|
|
|
|
|
Thanks for this chap ...
Jammer
if(glass == Glass.Empty){GoToBarAndOrderMoreBeer();}
else {Drink();}
My Blog | Article(s)
|
|
|
|
|
So really the upshot of this is that in order to actually convert BaseClass into a DerivedClass (rather than just changing references) is by explicitly mapping all the properties from BaseClass to DerivedClass?
Jammer
if(glass == Glass.Empty){GoToBarAndOrderMoreBeer();}
else {Drink();}
My Blog | Article(s)
|
|
|
|
|
Since both objects have different signatures, as far as I know you must copy eaach property separately. This can of course be done by explicitely setting each property but also by using reflection in which case you can create a small dynamic loop to set each property.
Previously I have used both techniques a lot, but since .Net Framework 2.0, when generics were introduced, I've been able to get rid of most of the reflection loops by using generic definitions. I'm not sure if they could help you in your case, but if you're not familiar with them, I believe that it's well spent time to have a look.
Hope this helps,
Mika
|
|
|
|
|
Thanks for this info Mika.
Jammer
if(glass == Glass.Empty){GoToBarAndOrderMoreBeer();}
else {Drink();}
My Blog | Article(s)
|
|
|
|
|
You're welcome
|
|
|
|
|
I am having a combobox on my windows form. i want to display some records in it which is in the datatable. The datatable contains only 1 column
(lets say column name is products).Inside the selected index changed event of combobox I write this line of code:-
// count is no of rows in my datatable
// dt is datable.
for(i=0;i<count;i++)>
{
Combobox1.Items.Add(dt.rows[i])
}
problem is that my combobox is not populating records,but my datable has all records of products column in it.I am using connected architecture.
|
|
|
|
|
rahul21 wrote: Inside the selected index changed event of combobox I write this line of code:-
Why do you want to populate at this event? Shouldn't it be on form load.
Next, once you have the data in datatable, you can directly bind the combobox using the datasource property.
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
rahul21 wrote: I am using connected architecture.
AFAIK, DataTable is not a connected architecture.
|
|
|
|
|
Hello!
Does anyone know how to send a ^ using the SendKeys class?
All other characters I tested work fine. ^ of course needs to be escaped using {^} (because ^ would press Ctrl), however when sending {^} it actually types a & ...
Best regards
Dominik
|
|
|
|
|
Hi,
noticed this on documentation:
If your application is intended for international use with a variety of keyboards, the use of Send could yield unpredictable results and should be avoided
while SendWait-method does not have this note.
Mika
|
|
|
|
|
Sorry, I should have pointed out that I'm already using the SendWait static method of the SendKeys class.
Any other idea?
Best regards
Dominik
|
|
|
|
|
If you change the keyboard layout to English, caret works just fine, but for example with Finnish layout, ampersand is sent instead caret (just like in your case). Since every other character works as expected, I would consider this as a possible bug.
Mika
|
|
|
|