|
Thanks for the reassurance. It would be nice if the was a function SendAndIWillWaitThankYou() but sadly not.
In this case I am happy to use a memory stream as I don't expect the generated files to be too large. I don't like the idea of loading in memory if they get too big so I may have to revisit this at some stage if they start growing
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: SendAndIWillWaitThankYou()
The email server may not have an Internet connection... or only 56K...
|
|
|
|
|
My code is on a separate thread anyway, so I don't mind it waiting however long. Perhaps in conjunction with the Timeout property I would be happy to wait say (30 minutes) and then log a failure
In the event it wants to queue the attachment and return control to me, I would much prefer it to make its own copy of the file to be queued, and then it can be responsible for the clean up itself
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I'd rather have a DeleteWhenSent property, so I don't have to worry at all.
And I don't really want to receive e-mails that you consider too large for storing them in memory...
|
|
|
|
|
Luc Pattyn wrote: nd I don't really want to receive e-mails that you consider too large for storing them in memory
Yes. In this case it is a 'If you really want it' function. Users have the option for an FTP transfer of the same files if they would prefer (recommended)
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Luc Pattyn wrote: I don't really want to receive e-mails that you consider too large
Neither do I, but you know those MBA-types and their love of Excel...
|
|
|
|
|
Hiya,
For me I found that disposing the client and or message releases the file lock.
Also, there is a problem sending emails over 4mb in size (this is if you do not know about it).
I would use the following: Net.Mail.Attachment.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit
kind regards
Dan
|
|
|
|
|
Agreed - the file remains locked until the Attachment instance is disposed. Calling Dispose on the MailMessage instance disposes of all attachments for the message.
protected virtual void Dispose(bool disposing)
{
if (disposing && !this.disposed)
{
this.disposed = true;
if (this.views != null)
{
this.views.Dispose();
}
if (this.attachments != null)
{
this.attachments.Dispose();
}
if (this.bodyView != null)
{
this.bodyView.Dispose();
}
}
}
public void Dispose()
{
if (!this.disposed)
{
foreach (Attachment attachment in this)
{
attachment.Dispose();
}
base.Clear();
this.disposed = true;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Did you try using your second approach, but with a FileInputStream (or whatever the dotNet equivalent is)?
Just change
Stream stream = new MemoryStream(File.ReadAllBytes(filename));
to
Stream stream = new FileInputStream(filename);
and retain the cleanup loop at the bottom.
This avoids the memory stream.
|
|
|
|
|
Thanks for the suggestion. I don't have time to test that at the minute but I have put a TODO so will give it a go at some point
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
The C# 4.0 compiler is slow on my 4-core laptop. I noticed only one core is busy when compiling. Is C# compiler multi-core aware?
|
|
|
|
|
AFAIK it is not. However you may be interested in this[^]. I haven't tried it yet.
|
|
|
|
|
Sorry, but the link is for C++ not C#...
Daniel Rühmer
Application engineer for Measurement Software
|
|
|
|
|
sorry, my mistake.
|
|
|
|
|
|
I am writting a windows service in .net 4.0 for monitoring purposeson regular intervals.
How is it possible to send an email from within this windows service please?
Thanks
|
|
|
|
|
|
I use this:
public static void
SendEmail
(
string Sender
,
string Recipient
,
string Subject
,
string Body
,
string SmtpServer
,
System.IO.FileInfo[] Files
)
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage ( Sender , Recipient ) ;
if ( Files != null )
{
System.Text.StringBuilder temp = new System.Text.StringBuilder ( Body ) ;
temp.Append ( string.Format
(
"\n\n{0} attached file{1}:"
,
Files.Length
,
Files.Length==1?"":"s"
) ) ;
foreach ( System.IO.FileInfo att in Files )
{
if ( att != null )
{
temp.Append ( "\n" + att.Name ) ;
if ( att.Exists )
{
msg.Attachments.Add ( new System.Net.Mail.Attachment ( att.FullName ) ) ;
}
else
{
temp.Append ( " -- does not exist!" ) ;
}
}
}
Body = temp.ToString() ;
}
msg.Subject = Subject ;
msg.Body = Body ;
System.Net.Mail.SmtpClient cl = new System.Net.Mail.SmtpClient ( SmtpServer ) ;
cl.UseDefaultCredentials = true ;
cl.Send ( msg ) ;
return ;
}
|
|
|
|
|
Here's how you bind to Dependency Property "CtrlXOffset" -
<UserControl x:Class="..."
x:Name="MyCtrl"
...
<aaa.SomeControl Name="xamTSChart" HorizontalAlignment="Left" VerticalAlignment="Stretch" VerticalContentAlignment="Stretch">
<aaa.SomeControl.RenderTransform>
<TranslateTransform
X="{Binding Path=CtrlXOffset, ElementName=MyCtrl, Mode=OneWay}"
Y="0" />
</aaa.SomeControl.RenderTransform>
</aaa.SomeControl>
...
</UserControl>
This is cool - I get the result I wanted.
However, can I do this with regular CLR Properties? How'd I rewrite the binding expression?
Thanks
http://en.csharp-online.net/WPF_Concepts%E2%80%94Dependency_Property_Implementation[^]
dev
|
|
|
|
|
You don't need to rewrite the binding expression. The binding engine also binds to POCO as well. BTW, you should have asked this in the WPF/Silverlight forum.
|
|
|
|
|
|
i use VS2005(C#2.0) and OS is Winxp.
i find some code like this:
[DllImport("dxva2.dll", EntryPoint = "GetMonitorTechnologyType", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetMonitorTechnologyType(
IntPtr hMonitor, ref NativeStructures.MC_DISPLAY_TECHNOLOGY_TYPE pdtyDisplayTechnologyType);
but i don't know how use it to get the local machine's monitor type.
Thank you!!!
modified on Monday, December 6, 2010 4:42 AM
|
|
|
|
|
A quick google using your subject line as the search term gave this at MSDN: How to detect display type : CRT or LCD ?[^] as the top link, which includes full source code.
Perhaps you should consider improving your Google-Fu?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
yes, i google it.the answer's development is vs2008,and i try to tranlate it to vs2005
but failed.but i think it should use the code just i pasted.
|
|
|
|
|
That code shouldn't be too difficult to convert down into a 2005 project/class. If you have specific problems related to this, perhaps you could post those issues to the Q&A section for specific answers which are much more difficult to present here in the forum.
I wasn't, now I am, then I won't be anymore.
|
|
|
|