|
Ah, after doing some testing, I've found what the Synchronized attribute does (and I think I now understand what you were saying).
[sycn attribute here]
void Test()
{
DoLengthy();
}
[sycn attribute here]
void Test2()
{
}
ThreadStart ts1 = Test;
ThreadStart ts2 = Test2;
ts.BeginInvoke(null, null);
ts.BeginInvoke(null, null);
Test2, despite doing absolutely nothing, will not finish until Test finishes! In other words, all methods with the synchronized attribute will be locked, not just the method being called. <Grrr> that stinks, I wonder what thinking went into that design. Well, I learned something new today.
Thanks for your insight.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
Hi,
I should first make it clear I know virtually nothing about c# & .NET (so please speak slowly and use short words )
I'm modifying a c# program someone else wrote which, as part of its process sends a mail using MailMessage.
This works... However when the message arrives some (not all) of the new lines (CR,LF) are messed up.
I noticed that if I open the mail in outlook and go View->Encoding this is set to "Western European (ISO)" if I switch this to "Western European (Windows)" the lines look right again.
So I looked into this and noticed the BodyEncoding member, but still can't get this working.
My code is
<br />
MailMessage mail = new MailMessage();<br />
<br />
mail.To = "me@somewhere.com";<br />
mail.Cc = "";<br />
mail.Bcc = "";<br />
mail.From = "Someone@SomewhereElse.com";<br />
mail.Body = <String read from a file somewhere>;<br />
SmtpMail.SmtpServer = "smtp.MyServer.com";<br />
SmtpMail.Send( mail );<br />
<br />
I have tried adding...
<br />
mail.BodyEncoding = System.Text.Encoding.GetEncoding(1252);<br />
and
<br />
mail.BodyEncoding = System.Text.Encoding.Default;<br />
but still the message is always displayed as "Western European (ISO)", does anyone have any idea how I can fix this?
Cheers
DAve
|
|
|
|
|
I have this really wierd error messgae popping up when I run my application (ASP.NET with C# code behind).
I am having the app create a log file and directing the stream to a share on the server.The wierd thing about this is...the application works fine from my machine but when I try the same on one of my fellow developers...it breaks out with this error message. I am not sure if this is a security issue because all of us have the same security settings.
I also turned impersonate=true and given my username and passsword for users in the web.config. and changed the setting in the local security settings per http://www.dotnet247.com/247reference/msgs/25/127951.aspx.
I cannot figure out what and where the trouble is...beacuse the stack trace is no help!!!
I appreciate anyone what can shed a light on this issue
Menita
|
|
|
|
|
This should be a simple answer, but I'm a bit stumped.
I have a Form with a GroupBox of minimum height acting as a visual seperator
in the form. When the Form loads I want only the upper portion of the window
to be viewable. To accomplish this I'm attempting to set the Height property of the form. My problem is how to I equate the location of my GroupBox seperator to the window height ?
-------------------
| |
| |
| |
| |
----------------- <- This is the Group Box I'm using as a seperator
| |
| |
| |
| |
| |
| |
| |
-------------------
|
|
|
|
|
To reduce the size of the form so that the GroupBox is not visible:
<br />
form1.Height = groupBox1.Top + (form1.Height - form1.ClientSize.Height)<br />
If the group box should be visible just add the height of it:
<br />
form1.Height = groupBox1.Top + (form1.Height - form1.ClientSize.Height) + groupBox1.Height<br />
|
|
|
|
|
Thanks Robert, I tried Height=GB.Top, but I didn't add the client size difference...thanks.
|
|
|
|
|
I am new to C# and I know this may be easy for most but I have a question and it may have to do more with variables between form.cs files and other cs files, but here goes. I know the easiest way to add custom buttons to a messagebox is to use a form and make my own. I am looking for a way to have "yes, yes to all, no, no to all" buttons on a messagebox. My question is, if I have a class not in a form cs file and I need to display this messagebox, how do I do this and make it modal, and how do I catch the values (in the none form cs class) of the button that is clicked by the user.
|
|
|
|
|
Calling ShowDialog of your MessageBoxForm will always show it modally and wait until the MessageBox is closed. As your MessageBox will have more result types than DialogResult can offer you will have to make your own enumeration and create a property where you can read the result form after the MessageBox is closed, e.g.:
MyMessageBox mmb = new MyMessageBox();
mmb.ShowDialog();
switch (mmb.Result) {
case MyMessageBoxResult.Yes:
case MyMessageBoxResult.YesAll:
...
}
To make the handling like the one of the original MessageBox just declare a static function in your MessageBox class which returns the result.
|
|
|
|
|
Hi All,
I've created a class library that interops with COM to allow it to be consumed by a COM application. From my development machine everything works great, the COM app recognizes and executes the library. However, when I try to deploy on a machine other than my own, the COMP application does not recognize the class library at all.
I've tried assigning a Strong name to the assembly, then user REGASM on the dll to no avail. I suspect I may need to register the dll with regsvr32 but I am uncertain about how to prepare my class library (I know I need to use GUIDGEN.exe to assign a GUID in an attribute somewhere in the code)...
Any pointers?
Thanks, Rein
|
|
|
|
|
MSDN has a good article on just that, here.
Tech, life, family, faith: Give me a visit.
Judah Himango
|
|
|
|
|
This seems like such a stupid question.... but how do i do it?
(I'll be kicking myself when someone gives me the answer)
Cheers
Cata
|
|
|
|
|
Elementary my dear Cata:
byteArray = BitConverter.GetBytes(varLong);
Let the kicking begin.
|
|
|
|
|
*kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick* *kick*
*ow*
|
|
|
|
|
I have a Form (MainForm) that loads a usercontrol (UserMenu) as a main menu, I do NOT want to show this as a dialog, but I have no way to fire an event on MainForm from a command button on UserMenu without instantiating a new MainForm.
There are properties set on the MainForm that need to be used. This is why I cannot simply instantiate a new MainForm.
I have considered delegates, but honestly struggling to wrap my mind around the concepts. Also, I know the showDialog is the simplist way, but cannot use it for various other reasons.
Any suggestions would be appreciated.
|
|
|
|
|
The best mechinism is delegates/events. The are pretty simplistic to use but, if you want to wimp out , just pass the form to the UserMenu and make the necessary methods public.
|
|
|
|
|
I definitely want to learn... do you know any good resources/tutorials on delegates/events. I have read through c# Unleashed and Windows Forms Programming in c#, but still am struggling to comprehend. Perhaps I am over analyzing this...
I will continue to read up on it.
|
|
|
|
|
This not MS way (they use EventArgs as the base) but here is a short snippet from one of my early project that may lead you in the right direction.
#namespace TabCode
{
public class TabChoice
{
public string Text;
public bool Active;
public TabChoice(string text, bool active)
{
Text = text;
Active = active;
}
}
public delegate void TabPanelChangeEvent(TabChoice choice);
public class TabPanel : Panel
{
private ArrayList _choices;
public TabPanelChangeEvent Change = null;
private void FireChange(int index)
{
if (Change != null)
{
Change((TabChoice)_choices[index]);
}
}
}
}
|
|
|
|
|
Thanks,
I was able to build a working delegate, the problem is I still have to instantiate a new copy of the form. I need to use the already instanciated copy of it because it has parameters and values that I need to use.
Any other thoughts??
|
|
|
|
|
Why don't you just tell the UserControl the parameters. If they change, update the UserControl.
I am not clear on what you are attempting to do but, creating a new copy of the form does not seem like a proper solution.
|
|
|
|
|
OK... my form loads a usercontrol that has a list of radiobuttons. This is not a modal form as they are always available for clicking. A command button on that form launches code on the main form. I have to know what radio button was selected and pass that back to the main form.
Here is the code so far:
In usercontrol:
public delegate void delRunStep(string name);
private void cmdRunStep_Click(object sender, System.EventArgs e)
{
//find out what radiobutton is selected
MainForm mf = new MainForm();
//This does not work as it makes new Mainform and looses all Data.
delRunStep run = new delRunStep(mf.RunStep);
run(myString);
}
In the main form:
public void RunStep(string StepName)
{
//do code
}
|
|
|
|
|
Why does the UserControl need to know what radio button is selected on the main form? Could it not just pass back that the command button was clicked and let the main form decide what to do with the information?
Otherwise:
If the UserControl has to be notified of the state of the radio buttons then let it listen.
public void RegistureRadioButton(RadioButton rb)
{
rb.CheckChanged += new EventHandler(OnCheckChange);
}
private void OnCheckChange(object sender, EventArgs ea)
{
RadioButton rb = (RadioButton)sender;
if (rb.Checked)
{
if (rb.Text == "Choice 1")
{
}
}
}
|
|
|
|
|
The Userform has the Radiobuttons. But what you are saying will work,if I switch it around and make the main form know what radiobutton is selected. I will keep on working on it. I think I have enough info to make it work.
Thanks.
|
|
|
|
|
It may be that I dont really get the problem but as Micheal already mentioned you could just pass the existing form to your user control. Give the usercontrol a property where the form can be set and than use this instance:
(within MainForm)
<br />
UserMenu menu = new UserMenu();<br />
menu.MyMainForm = this;<br />
This is probably the easiest way, but an event should be better. For that you have to decalre an event in UserMenu and consume it on the MainForm (just like you would handle the Click event of a Button).
|
|
|
|
|
I want to do it the best way. I added code in the above post. I do appreciate all the help.
|
|
|
|
|
I used the tutorial at http://www.codeproject.com/csharp/cpimpersonation1.asp to try to perform an impersonation.
The code seems to run fine, and when I execute it there must be some sort of sign on happening. The reason I say this is because when I actually do try to sign on with incorrect user name or password it does throw an exception (as it should).
Anyways, when the code goes to access some file off of a local computer that only my account should have access to, it doesn't work, and the program says it failed to open the file sucessfully. Any suggestions?
Cheers,
Jim
|
|
|
|