|
SummerBulb wrote: My dillemma is concerning the CPU, memory and internet bandwidth.
It'd be a premature optimization. I'd suggest to make the application working first. Profile it and see whether it requires optimizations. BTW, you can consider few things when you develop.
1 - Ensure calls to Dispose() for all disposable objects - CLR manages the memory quite well and you don't have to worry much about it. Few classes in the .NET framework implements IDisposable and make sure you call Dispose() method on it to avoid resource leaks.
2 - Don't send unnecessary informations over the wire - I have found WCF services perform better than SOAP based web services. But you need to understand how WCF does the communication. When you send large objects/collections, it will be slow. So make sure you send only the necessary information.
Once you done with the application, profile it and find out the areas that can be optimized further.
Best wishes,
Navaneeth
|
|
|
|
|
Thank you very much for your replies.
Does the WCF differ much from the SOAP? (this must sound like a very silly question to someone whoe knows them both well...)
modified on Sunday, December 6, 2009 4:51 AM
|
|
|
|
|
SummerBulb wrote: Does the WCF differ much from the SOAP?
Yes. SOAP is a protocol where WCF is a framework for creating service oriented applications. WCF can communicate using SOAP protocol if needed. Here[^] is a good MSDN article on WCF's capabilities.
Best wishes,
Navaneeth
|
|
|
|
|
What's the "fixed interval"?
If "almost immediately" is less than 5 minutes, consider to could connect to a server, stay connected, and receive an event when there's a new task. No polling required, tasks arrive immediately.
If you're using WCF, you can do this Duplex Services[^].
|
|
|
|
|
I've had good success with having a Windows Service poll a database to get information on tasks to perform.
It could use a Web Service to access the database.
You can also define a custom action for the Windows Service that will allow the server to trigger the action of the client.
|
|
|
|
|
I am working on a Invoice Application in which a user can enter in the invoice line items by selecting the item number from a combobox within a DataGridView. I am looking for some sample code to do the following:
1. load a combox within a datagridview from a table
2. load other fields (item descr, item price from combobox table)
As always, thanks for the advice.
|
|
|
|
|
Try google. Copy and paste your first question into it's text box, and press search. It finds your answer, and even offers to correct your spelling at the same time!
Repeat.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
"Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"
|
|
|
|
|
I have an object named 'dv'
'dv' has a string property named 'refNumber'
There is also a string 'altString' = "refNumber"
Is there a way to use 'altString' to get that property from 'dv'?
string newString = dv.??altString??
-- should set newString the same as --
string newString = dv.refNumber
Thanks for your suggestions.
|
|
|
|
|
Reflection can do this. Use System.Reflection name space. You'd do something like (not tested)
PropertyInfo property = (PropertyInfo) dv.GetMembers().SingleOrDefault(info =>
info.MemberType == MemberTypes.Property &&
info.Name == altString);
string newString = string.Empty;
if (property != null)
newString = (string) property.GetValue(dv, null);
Best wishes,
Navaneeth
|
|
|
|
|
Thank you. Please forgive my ignorance, but where does 'refNumber' occur in your reply?
|
|
|
|
|
BDJones wrote: but where does 'refNumber' occur in your reply?
Quote Selected Text
You said it will be in altString variable. I am using that variable to compare against name. You can replace it with "refNumber" if you wish to.
Best wishes,
Navaneeth
|
|
|
|
|
|
|
|
Hi all,
how we can use the enum any simple Example of using the enum?
enum is data type or object?
Hope hear from you
Best Regards
|
|
|
|
|
Rameez Raja wrote: any simple Example
public enum Response
{
No
,
Yes
}
return Response.Yes ;
Rameez Raja wrote: enum is data type or object?
Read up on it[^] and then ask any specific questions you have.
|
|
|
|
|
Hi,
i can able to insert random letters in TableLayoutPanel with this code
private void form_Load(object sender, EventArgs e)
{
for (int a = 0; a < tableLayoutPanel1.ColumnCount; a++)
{
for (int b = 0; b < tableLayoutPanel1.RowCount; b++)
Random r = new random();
lable nl = new lable();
int x = r.nest(65,90);
char c = (char)x;
nl.text = c.tostring();
tableLayoutPanel1.Controls.Add(nl, a, b)
}
}
}
i couldn't able to insert chosen words into TableLayoutPanel .pls help me.
how to change the color of letters when they click answer.
thanks in avance.
|
|
|
|
|
Hi,
please use PRE tags to show code.
and show real code, something that might be acceptable to a compiler.
your code is filled with minor mistakes.
also don't create new Random() instances all the time, use one Random() over and over.
Add a Click handler to each Label, so you can change its color; you can reuse the handler for all Labels, and use its sender to identify which Label got clicked.
From what you show and ask, I expect you are pretty new to C#, and would benefit from studying a C# book to properly learn the basics.
|
|
|
|
|
Why does it call two ReferenceEquals methods when only one is needed? I have tried removing the one with null as a parameter and it works exactly the same. I don't understand its purpose.
return !ReferenceEquals(null, obj) &&
(ReferenceEquals(this, obj) || obj.GetType() == typeof(Foo) &&
Equals((Foo)obj));
|
|
|
|
|
When you override Equals() , you are saying that "your class objects has value equality rather than reference equality". The suspected code here is doing just a null check before doing the value equality. Calling members on a null reference will lead to exception. It can't just use if(obj == null) because if operator == is overloaded on the type and it calls Equals to do the equality, you will end up in infinite loop. Usually it is a recommended practice to overload operator == if you have overridden Equals and call Equals from operator overload.
Having said that, resharper is stupid in generating Equals and GetHashCode . You should never rely on the code what it generated. Resharper includes mutable objects in the hashcode calculation which will lead into severe issues.
Best wishes,
Navaneeth
|
|
|
|
|
I'm trying to:
1st Create an array containing ref's to labels.
2nd Initiate them with a for loop and add some text to the label.
3d Add them to a panel with controls.add() either in the same loop or afterwards
The problem:
My code below sort of works but it will just add 1 control instead of 4 in my dummy example... what I'm I missing here??
I am aware I'm not setting any location Point prop's in the code below but im sure that isnt the problem...
private void btnExampleClick(object sender, EventArgs e)
{
Label[] lbl = new Label[4];
for (int i = 0; i < 4; i++)
{
lbl[i] = new Label();
lbl[i].Text = i.ToString();
}
foreach (Label x in lbl)
{
Controls.Add(x);
}
}
|
|
|
|
|
Hi,
welcome to CodeProject.
please use PRE tags when showing code, or select the code and use the "code block" widget.
why are you having a separate loop to add the labels to the Controls, you could do that in the first loop.
You did add 4 labels, however you need to set the label's Location, they are all on top of each other.
|
|
|
|
|
I am having a hard time figuring this out. My applications is using WMI to get information about a remote computers disk drives, installed applications, and services (all of this works fine). I can seem to get all this information but I cannot get the computer to stop a remote service.
I keep getting "RPC server is unavailable". How is this possible? I am able to retrieve information from these computers so it can't be unavailable.
At first I kept getting 'Access Denied' errors. I was trying to make it use the windows username and passwords somehow instead of having to enter a username and password.
So now I'm doing this:
ConnectionOptions conn = new ConnectionOptions();
conn.Impersonation = ImpersonationLevel.Impersonate;
conn.Username = "DOMAIN\username";
conn.Password = "password";
conn.EnablePrivileges = true;
Like I said.. I can connect and get all the information in the world I want, but cannot seem to stop a service. I read this other article about settings permissions and I have already tried that by going through computer management on the server.
Oh and by the way I am using the top domain admin user to do this.. so there is not another user in this domain that has more rights.
If you are interested in the whole code it is here: (Thanks to (Windows Management Instrumentation (WMI) Implementation[^]) for most of it)
ServiceInfo service = (ServiceInfo)serviceInfo;
ManagementOperationObserver observer = new ManagementOperationObserver();
MyHandler completionHandlerObj = new MyHandler();
observer.ObjectReady += new ObjectReadyEventHandler(completionHandlerObj.Done);
try
{
ConnectionOptions conn = new ConnectionOptions();
conn.Impersonation = ImpersonationLevel.Impersonate;
conn.Username = "DOMAIN\username";
conn.Password = "password";
conn.EnablePrivileges = true;
ManagementScope scope = new ManagementScope("\\\\" + service.DNSHost + "\\root\\CIMV2", conn);
scope.Connect();
ManagementObjectSearcher mos = new ManagementObjectSearcher(scope, new ObjectQuery("SELECT * FROM Win32_Service WHERE DisplayName='" + service.item.Text + "'"));
foreach (ManagementObject mo in mos.Get())
{
bool Started = Convert.ToBoolean(service.item.SubItems[1].Text);
if (Started)
mo.InvokeMethod(observer, "StopService", null);
else if (!Started)
mo.InvokeMethod(observer, "StartService", null);
int intCount = 0;
while
(!completionHandlerObj.IsComplete)
{
if (intCount > 10)
{
MessageBox.Show("Terminate process timed out.", "Terminate Process Status");
break;
}
System.Threading.Thread.Sleep(500);
intCount++;
}
if (completionHandlerObj.ReturnObject.Properties["returnValue"].Value.ToString() == "0")
{
if (!Started)
{
service.item.SubItems[1].Text = "True";
service.item.SubItems[1].BackColor = Color.LimeGreen;
service.item.SubItems[1].ForeColor = Color.Black;
}
else
{
service.item.SubItems[1].Text = "False";
service.item.SubItems[1].BackColor = Color.Red;
service.item.SubItems[1].ForeColor = Color.White;
}
}
else
{
MessageBox.Show("Failed.", "Start/Stop Service Failure");
}
}
}
catch (Exception ex) { MessageBox.Show("Error starting/stoppping service.\n\n" + ex.Message); }
finally
{
Invoke((Action)(() => { picProgressServices.Visible = false; }));
}
}
|
|
|
|
|
I guess I could always use a ServiceController. I was able to get taht to work great. Would still like to understand more why the wmi is being so difficult
|
|
|
|
|
How can I use the mouse event to move object
|
|
|
|