|
Well, IMHO ReferenceEquals method, when used to compare a reference with null , it's merely redundant.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
That would depend on where it is used.
For example: When you override the == operator, you may want to use ReferenceEquals() so that you don't end up with an infinite loop or other undesired effect.
|
|
|
|
|
override operators... you can do that?
My current favourite word is: Waffle
Cheese is still good though.
|
|
|
|
|
public static operator bool == (MyObject lhs, MyObject rhs)<br />
{<br />
}
|
|
|
|
|
|
Hello,
I'm looking for a way to activate an existing browser session by means of a C# .Net executable.
I have found some code where I would be able to look for all active programs, and eventually even kill them. I did not find a way to activate a process, however.
private void button1_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process[] myProcesses;
myProcesses = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process instance in myProcesses)
{
MessageBox.Show (instance.MainWindowTitle);
instance.Kill();
}
}
I need this to avoid the user to have logged in again.
I want to activate his open internet session, and eventually even refresh his session with a new url.
E.g.
http://localhost/sid=abc123?nameId=10
should be replaced by
http://localhost/sid=abc123?nameId=20 , in the same session, and triggered by an executable.
Is this possible ?
Help would be very much appreciated.
|
|
|
|
|
I doubt it's possible.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hai all,
I have to send mails through MAPI.
I have gone through the articles given in code project.
I have created a sample application. But when the send() method is called it is prompting a dialog box intimating an application is trying to send mail automatically... ... from the Microsoft outlook application. While clicking on the "Yes" option it is sending the mail.
But the above task should be automated in my module and it has to be done in a windows service.
Can any one give me a solution to perform the above without displaying the message box.
Thanks a lot in advance.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
Is there a reason you have to use MAPI over SMTP?
In this[^] example they specify the user cannot edit the message (which I believe means it is not shown to them).
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Yes, because i have to have the items in the "Send Items" folder of the outlook.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
That makes sense. Can you post the code that you are using to call MAPISendMail?
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
The code is:
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using Microsoft.Office.Core;<br />
using Outlook = Microsoft.Office.Interop.Outlook;<br />
<br />
namespace ExchangeMAPI<br />
{<br />
public partial class MailUsingMAPI : Form<br />
{<br />
public MailUsingMAPI()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void btnSendMail_Click(object sender, EventArgs e)<br />
{<br />
object missing = System.Reflection.Missing.Value;<br />
<br />
Outlook.Application outlookApplication = new Outlook.Application();<br />
Outlook.NameSpace nameSpace = outlookApplication.GetNamespace("MAPI");<br />
<br />
nameSpace.Logoff();<br />
nameSpace.Logon(missing, missing, true, false);<br />
<br />
Outlook.MailItem mail = (Outlook.MailItem)outlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);<br />
mail.To = txtReceiverAddress.Text;<br />
mail.Subject = txtSubject.Text;<br />
mail.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;<br />
mail.HTMLBody = "<html><body><p>" + txtMessage.Text + @"</p></body></html>";<br />
mail.Send();<br />
}<br />
}<br />
}
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
You are using the Outlook interop, not MAPI (even though you are getting the MAPI namespace). If you look at the documentation[^] for the MailItem.Send method, you will see that it says the dialog will be shown. This is a security measure, so I doubt you would be able to programmatically suppress it.
You should be able to configure the Outlook UI to suppress it though (depending on your version). I'm running Outlook 2007, and I can disable it under the "Tools->Trust Center..." menu item. In the dialog select "Programmatic Access", and select the "Never warn me..." option. This is not recommended by Microsoft or me.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I am using Microsoft Outlook 2003, so where can i find this option.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
Sorry, I don't have Outlook 2003, so you'll have to find it yourself. This[^] may help though.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
Hi,
I'm new to programming in C#, actually learning under someone. I recently saw the following line of code in the code-behind of an ASP.NET Web application page :
//all the other autogenerated codes
static DataSet dSet; // explain this line please.
What does it mean to make a DataSet static?
Thanks for your time.
Obinna from Nigeria.
|
|
|
|
|
ObinnaAj wrote: What does it mean to make a DataSet static?
Hi, Obinna. In an ASP.NET project, this makes no difference, because of how ASP.NET works. In general, it means that if you have a class like this:
class Widget
{
public static int widgetCount = 0;
}
then the value of widgetCount is the same across all instances of the program. If the Widget constructor looked like this:
public Widget()
{
++widgetCount;
}
Then, every widget would have the same value, and it woild not be 1, it would be equal to the number of widgets that had been created. In fact, in C#, if you do this:
Widget w = new Widget();
int n = w.widgetCount;
The compiler would not allow it. You need to do this:
int n = Widget.widgetCount;
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: public Widget()
{
++widgetCount;
}
Could you tell any sample scenario where we need to use this kind of increment ? i don't find any use of incrementing the static value.
|
|
|
|
|
Well, a count of objects seemed like a decent real world example. Another may be a database connection string. Basically, if the value is always the same, or if it is a value you want to be able to make all instances aware of, static does that for you.
Once you know how it works, if you ever need it, you'll know.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: In an ASP.NET project, this makes no difference, because of how ASP.NET works.
As an ASP.NET application is multi threaded, it makes a huge difference. A static variable will be shared across all threads, so they are rarely used at all in ASP.NET applications.
If you want to have some data that is used by all threads, it's often better to put it in the Application.Items collection, and populate it from Application_Start in global.asax.
---
single minded; short sighted; long gone;
|
|
|
|
|
So, if you store something as a static variable in a page, when a new page instance gets created, that value has been stored ? I didn't think so.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: So, if you store something as a static variable in a page, when a new page instance gets created, that value has been stored ?
Yes. The static variable belong to the class rather than the class instance. The static variable exists before there are any instances.
---
single minded; short sighted; long gone;
|
|
|
|
|
So does it mean that the content of the instatiated DataSet cannot be changed anywhere in the program? what exactly?
//obinnaaj Eof
|
|
|
|
|
You can change the DataSet, but then you have to use locking for every access to it, so that one thread can't read it while another thread is changing it.
---
single minded; short sighted; long gone;
|
|
|
|
|
Hi Obinna,
Going back a bit because you're probably not familiar with multiple threading yet, the static keyword marks the variable as being shared across all instances of the class.
so for instance if you have a class member which is an int:
public class MyClass
{
int z;
}
each and every instance of that class you create (new MyClass() ) will have its own z, which can and usually will be different.
when its static:
public class MyClass
{
static int z;
}
then each and every instance shares just a single z. If you change it in one instance, it will change in all instances. As said previously, this could be useful if you wanted to maintain a count of how many instances are in existence and have that variable in class scope.
Similiarly, if you had a database connection string, that would be the same for each instance so you would mart it static so that you didn't create multiple copies of the same thing but instead just have one which each instance can access.
Regards,
Rob Philpott.
|
|
|
|