|
You possibly need to implement the IDisposable pattern.
This will help you clean up your unmanaged resources and also call disconnect (possibly) before the Dispose() method is called.
My signature "sucks" today
|
|
|
|
|
Hello!!
I'm pretty new in .Net and now I'm using C# to do some test automation with System.Windows.Automation.
I Need to do a click on an specific area of the main window from the application that I want to test, this is defined as WindowPattern, Do you know how could I do this??
modified on Tuesday, June 1, 2010 3:01 PM
|
|
|
|
|
I'm trying to determine if its possible to get the row index of the data combination while avoiding the interation for-loop?
Here's an example below
DataTable may look like this (with variable named "datTab":
Name Number1 Number2 Number3 Number4
Ron 60 43 33 40
Sco 83 43 33 42
Alb 60 43 32 40
Hei 34 32 45 55
Ant 23 43 33 23
Now, the question is... is it possible to get the row index number if I would find the number combination with 4 numbers? Such as I would say to find 60, 43, 33, 42 and it would find the row index = 1. I understand it can do for one column, such as
int indexTab = datTab.Rows["Number1"].IndexOf("00");
but with multiple columns? I just thought of it as I use it in my code and the software is really sluggish with muliple columns using For-loop and if-statement inside the loop.
I hope someone can answer this. I'm hoping this will provide better performance.
Thanks!
|
|
|
|
|
select ROW_NUMBER() OVER(ORDER BY Name) AS RowNumber,Name,Number1,Number2,Number3,Number4
Then use a RowFilter on the default view to narrow down to the record you want and get the value of the RowNumber column.
|
|
|
|
|
can you provide an example? I'm not sure if I quite understand what you're saying.
|
|
|
|
|
Even if you don't write the iteration, it'll be there. I prefer to write my own stuff so I know what's going on, rather than wondering what's going on behind the scenes.
P.S. You could even write your own indexing using a hierarchy of Dictionaries.
|
|
|
|
|
You could have your fifth column be a combination of the numbers. So, the first row would have a "ComboColumn" value of "60,43,33,40". If you have a SQL query fill your DataTable, you could just have it return that "ComboColumn" in addition to the other columns. You could then use datTab.Rows["ComboColumn"].Indexof("60,43,33,40") to find the correct row. However, if that is still too slow, you may want to condider creating a dictionary object to hold the rows with the ComboColumn string as the key. Alternatively, if you are just looking for a single row and you are using SQL, it might be a good idea to just query for that specific row rather than gather data then find it. If you have an appropriate index setup on the table, that should be very fast (also depends on network speed and such).
|
|
|
|
|
hmm ComboColumn may be a good idea... I'll give that a shot and see what happens.
|
|
|
|
|
I am playing with a small program that sends emails through SMTP server. This is a C# Windows Forms application. The main part of the program looks like this:
using System;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
namespace test_email_smtp
{
public partial class send_mail_through_smtp : Form
{
public send_mail_through_smtp()
{
InitializeComponent();
}
private void send_mail_Click(object sender, EventArgs e)
{
SmtpClient client = new SmtpClient(smtp_server.Text);
MailMessage message = new MailMessage(send_from.Text, send_to.Text);
message.Body = mail_body.Text;
message.Subject = mail_subject.Text;
client.Send(message);
message.Dispose();
}
}
}
"send_from", "send_to", "mail_body", "mail_subject", and "smtp_server" are TextBox controls on the Form.
When I ran the program and click the "send" button, and then close the program (by closing the form), the mail is sent IMMEDIATELY.
However, if I click the "send" button and leave the program running (not closing the program), after a minute or so, I will get a message saying "Your mail message was unable to be sent because the connection to your mail server was interrupted. Please open your email client and re-send the message from the Sent Messages folder." This does not happen all the time. I'd say 9 out of 10 times this message was shown. The one time it was not shown, the mail was sent after a long time.
By the way, the message is from "Symantec Email Proxy". When this message was shown, a balloon message was also popped up by the system tray area saying "Scanning message 1 of 1", also from Symantec.
All these problems do not exist if I close the program after I click the "send" button. The mail will be sent immediately. I need the program to keep running after the mail is sent. I can't close the program every time a mail needs to be sent. Any ideas? Thanks!
|
|
|
|
|
Trying disabling your antivirus to see if you get the same problem.
If you don't, then it has something to do the the symantec firewall or virus scan.
My signature "sucks" today
|
|
|
|
|
I have verified that the antivirus software running on my machine was the problem. Your help is appreciated.
|
|
|
|
|
The suggestion made by Abhinav may help; if it does not, then:
SmtpClient implements IDisposable so it may be that the email is sent when the client is disposed. This would give the symptoms you describe, at least in terms of the send-when-application-closed problem. Try wraping your section in a using block.
using (SmtpClient client = new SmtpClient(smtp_server.Text))
{
MailMessage message = new MailMessage(send_from.Text, send_to.Text);
message.Body = mail_body.Text;
message.Subject = mail_subject.Text;
client.Send(message);
message.Dispose();
}
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Thanks for your reply. I tried that and got the following compile time message:
Error 1 'System.Net.Mail.SmtpClient': type used in a using statement must be implicitly convertible to 'System.IDisposable'
I will do more research on this matter. Thanks!
|
|
|
|
|
My apologies, it looks like MS are lying again... SmtpClient @ MSDN[^]
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
OriginalGriff wrote: it looks like MS are lying again
Hmm. Continuously improving themselves, that is what they are doing. It took them till 4.0 to realize SmtpClient had to implement IDisposable.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
After disabling the antivirus program, the original program sends the email immediately when the button is clicked. That indicates that the antivirus was the problem.
I still don't understand why closing the program bypasses the antivirus program's scanning of the email.
Another issue is that it's hard to ask the program's users to turn off their antivirus program to facilitate the healthy running of my program.
My solution to the problem may be to use separate processes for sending emails. I can spawn a small program just to send an email. It terminates by itself right after the mail is sent.
Thank you for your time!
|
|
|
|
|
loyal ginger wrote: Another issue is that it's hard to ask the program's users to turn off their antivirus program to facilitate the healthy running of my program.
I can see where that might be a problem.
loyal ginger wrote: My solution to the problem may be to use separate processes for sending emails. I can spawn a small program just to send an email.
But if you gotta, you gotta. What kind of virus scanner are we talking?
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
I have "Symantec AntiVirus" version 10.1.5.500 on my development machine. It's hard to predict what antivirus software will be on my client's machine. I am lucky to see this happen on my machine. Sometimes a fully tested application craps out on client's machines because some other software's interference, making the software developers look bad. I hope that does not happen to me.
|
|
|
|
|
I would suggest you try .NET 4.0 and use the new SmtpClient.Dispose() method (directly or through a using statement, doesn't matter). I haven't done so myself yet, but it seems to be a new enhancement by MS, and I expect it to solve your problem.
Of course, you should not disable or replace your AV.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Hi all!
I've tried to create file using File.Open(filePath, FileMode.Create) where filePath contains Unicode symbols. I can see those specific symbols in the explorer but if I try to read folder content via cmd dir I see only "Filename (??????? ???)" where question char replaces desired symbols.
Even more. When I tried to open file from the Explorer I received an error "file does not exist". But opening from cmd with (?????) is OK.
Can anybody help me? Thanks in advance
|
|
|
|
|
My advice is to not use unicode characters in paths/filenames.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
how to get the number of words in .doc OR .docx (MicrosoftWord file).
I will give the address of word file and i wanna get the number of words in it.
Thanks
|
|
|
|
|
Find the number of bytes, divide by two.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
OriginalGriff wrote: Find the number of bytes, divide by 42.
FTFY.
I don't think they have cut down on the overhead.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Tools | Word count
|
|
|
|