|
Hello,
I am trying to execute the following code from a background worker's DoWork Event Handler and getting the error :Cross Thread Operation etc..etc... Can you kindly show me some ways to do this work. The following code does Extract Text from a MS word document file.
string textData ;
try
{
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.ApplicationClass();
object nullobj = System.Reflection.Missing.Value;
object file = fileName;
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(ref file, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj,
ref nullobj, ref nullobj, ref nullobj, ref nullobj);
doc.ActiveWindow.Selection.WholeStory();
doc.ActiveWindow.Selection.Copy();
IDataObject data = Clipboard.GetDataObject();
textData = (data.GetData(DataFormats.Text)).ToString().Trim();
doc.Close(ref nullobj, ref nullobj, ref nullobj);
app.Quit(ref nullobj, ref nullobj, ref nullobj);
}
catch (Exception error)
{
MessageBox.Show("Error Extracting Resume Text : " + error.Message);
}
-- modified at 16:24 Sunday 5th March, 2006
|
|
|
|
|
My guess is that the code that you're running happens to raise an exception and hit the line that displays a MessageBox. That operation is not allowed on a background thread so that's probably where it yells at you.
Try commenting out the "MessageBox.Show.." line and see if you still get that error.
Have you verified that yet?!
----
www.muzikstor.com
|
|
|
|
|
Hi,
Thanks for the reply. Actually I did not have problem showing Message Box in background worker thread. The error showing because it is acessing MS word file, openning it, selecting the text, copying the text and then a string is getting value of the selected copied text. And this selecting the text is being prohibited by background worker. OR can you show me some other way to extract TEXT from MS Word ? Even if I find a free command line MS word to text converter, I will be happy. I will use Diagnostics.Process in that case/
Thanks
|
|
|
|
|
Well, using COM Interops can be tricky. Whenever you work with COM automation you have to be mindful of the threading model of your application. Have you tried running your code in the main thread (not in the background worker thread)?
If so, and it works.. try creating the secondary thread manually instead of using the BackgroundWorker object. That may help.
Other than that, I'm running out of good ideas :p
----
www.muzikstor.com
|
|
|
|
|
Hi,
Thanks for your reply. Yes, This code is working excellent without Background Worker ( I mean, within Main Thread ). So, I will try using manual thread. I thought Background worker and manually created Thread are exactly same thing.
|
|
|
|
|
They are similar but as far as I know, the Background Worker thread object implements some extra functionality to properly marshal the calls between the threads. The funny thing is that it's supposed to fix just the type of problem you were experiencing. I'm surpized..
As I said earlier, I think you need to delve deeper into the details of the COM+ threading model and interacting with it from the a .NET mannaged thread.
----
www.muzikstor.com
|
|
|
|
|
Hi..
I want to creat my own smiley (draw it myself)
I have created a circle with the
System.Drawing.Graphics gf;
//Here i make the circle
gf.DrawEllipse(new Pen(Color.Black), 85, 50, 30, 30);
//Here I added 2 smaller cirles to be the eyes
gf.DrawEllipse(new Pen(Color.Black), 94, 59, 3, 3);
gf.DrawEllipse(new Pen(Color.Black), 104, 59, 3, 3);
but then my problem is to make the happy/sad mouth
it should be as simple as the good old smiley " or
I have tried by using the
gf.DrawCurve(-I had addes some values here-);
But I could not get it to work
Can anyone help me haw to draw this?
Thanks
QzRz
|
|
|
|
|
Try something like:
gf.DrawArc(new Pen(Color.Red), 90, 55, 20, 20, 45, 90);
---
b { font-weight: normal; }
|
|
|
|
|
Thanks for the fast reply
It works just fine, thanks
|
|
|
|
|
Hello,
I am trying to create an e-mail application. I have created a simple mail application in win forms. The user will put in the fields and click the send button.
I am not really sure how an e-mail application works. But if send an e-mail to my e-mail account i.e. steve1_rm@hotmail.com. I send the e-mail. However, I never receive the e-mail that I send using this mail application. The application works ok, and there are no run-time errors. Is there something I need to do, to be able to send this to my hotmail, yahoo, or gmail e-mail accounts.
The code I have used is below. This has been written in C# Visual Studio 2005.
Thanks in advance
<br />
using System.Web.Mail;<br />
<br />
private void btnSend_Click(object sender, EventArgs e)<br />
{<br />
try<br />
{<br />
MailMessage aMessage = new MailMessage();<br />
aMessage.From = txtFrom.Text;<br />
aMessage.To = txtTo.Text;<br />
aMessage.Cc = txtCC.Text;<br />
aMessage.Bcc = txtBCC.Text;<br />
aMessage.Subject = txtSubject.Text;<br />
aMessage.Body = txtMessage.Text;<br />
<br />
if (txtAttachment.Text.Length > 0)<br />
{<br />
aMessage.Attachments.Add(new MailAttachment(txtAttachment.Text, MailEncoding.Base64));<br />
}<br />
<br />
SmtpMail.Send(aMessage);<br />
<br />
MessageBox.Show("Message sent to " + txtTo.Text, "E-mail Program", MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message.ToString());<br />
}<br />
|
|
|
|
|
You need an SMTP server. If you don't have one installed on the computer you are running, specify the address of the SMTP server to use in the SmtpServer property in the SmtpMail class.
---
b { font-weight: normal; }
|
|
|
|
|
I recently got bored and made an e-mail aplication. Using my ISP's mail server worked for me. Also I noticed that you are using System.Web.Mail namespace. In C# 2.0 this is obsolete. System.Net.Mail is the one that the compiler reccommends, however it is not required.
Ex.
using System.Net.Mail;
using System.Net;
...
try
{
using (MailMessage message = new MailMessage("me@hotmail.com", "you@gmail.com", "Test", "This is a test"))
{
message.IsBodyHtml = true;
SmtpClient mailClient = new SmtpClient("smtp.execulink.com");
mailClient.UseDefaultCredentials = true;
mailClient.Send(message);
}
MessageBox.Show("Message Sent");
}
|
|
|
|
|
Hello
I have just found some useful information. I have configured the IIS smtp virtual server.
In the general settings l have add my IP address.
In the access tab, click rely button and granted access to my IP address.
I have added this code:
Code:
<br />
Smtp.MailServer = "localhost"; <br />
or<br />
Smtp.MailServer = "127.0.0.1";<br />
But l am still getting the same error message "Transport failed to connect to server".
I have added this code:
<br />
Smtp.MailServer.Insert(0,"localhost");<br />
This time I don't get the error message, but did not receive any e-mail to my yahoo account.
I am using winforms not asp, not sure if this makes any difference.
Any ideas on how to solve this.
Many thanks,
Steve
|
|
|
|
|
Smtp.MailServer = "mail.hotmail.com";
Smtp.MailServer = "mail.gmail.com";
|
|
|
|
|
Be advised that most "Freemail"-Providers do not accept messages which have conflicting Sender-Address and Sender-IP/Hostname information.
That is, they would drop a message from test@hotmail.com if the server sending the message does not belong to hotmail (e.g. sender-address is "test@hotmail.com", sending server is "mail.gmail.com").
Be sure to use the SMTP-Server your Mail-Provider has given your for that address.
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Hello,
I made the changes to the SmtpMail.SmtpServer = "mail.hotmail.com";. My listing for sending the code is illistrated below. But still does not work. I am sending the e-mail to my hotmail account steve1_rm@hotmail.com, but never gets there.
<br />
MailMessage aMessage = new MailMessage();<br />
aMessage.From = txtFrom.Text;<br />
aMessage.To = txtTo.Text;<br />
aMessage.Cc = txtCC.Text;<br />
aMessage.Bcc = txtBCC.Text;<br />
aMessage.Subject = txtSubject.Text;<br />
aMessage.Body = txtMessage.Text;<br />
<br />
if (txtAttachment.Text.Length > 0)<br />
{<br />
aMessage.Attachments.Add(new MailAttachment(txtAttachment.Text, MailEncoding.Base64));<br />
}<br />
<br />
SmtpMail.SmtpServer = "mail.hotmail.com";<br />
<br />
SmtpMail.Send(aMessage);<br />
<br />
MessageBox.Show("Message sent to " + txtTo.Text, "E-mail Program", MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
Is there something I am doing wrong, or something I am not doing.
Thanks in advance,
Steve
|
|
|
|
|
check this
http://www.c-sharpcorner.com/1/send_mai1l.asp
http://deedee.brainstream.net/SimpleSmtpMailCExampleASPNET.aspx
|
|
|
|
|
Hello
I have found some information on another post that told me that you cannot directly send e-mails from the outside to hotmail, yahoo, etc. In order for you to do this you have to send a username and password to be authenticated for hotmail, yahoo, etc. I thought it was possible to send e-mails to these accounts.
I did what you suggested and my code is similar to yours. I deleted the mails from inetpub/mailroot/queue and restarted IIS. But still did not work.
Any other suggestions about this I would be most grateful.
Thanks,
Steve
|
|
|
|
|
I am interested in playing around with some IO in C#. Could someone point me out to some articles about IO with a USB port in C# 2.0?
Thanks,
Sean
|
|
|
|
|
The only thing I've come across is IC#Code's #usblib
But I don't think it's been updated in a long time.
Another alternative is to use the SerialPort class and specify a usb port to open (this works in the old MSComm control). I'll try and remember how the ports are named , this will allow you to use the USB port like a Serial Port
Ed
|
|
|
|
|
Thanks
|
|
|
|
|
QuickUSB is what I used. But, it's driver interface was only exposed/documented/exampled in C++. SO, I made a handy C# wrapper class. But of course, this only works with quickusb usb 2.0 chips...
/\ |_ E X E GG
|
|
|
|
|
Anyone know of anything that causes a window form to lose its handle and regenerate it? Got a form whose handle changes after form load and wondering if there is any common cause?
Thanks
Aj
|
|
|
|
|
If I am not mistaking a form's handle does not changes. It represents a global unique id of a window, allocated at the creatin of the window. But if you use a static field and compare it withe various instance hadles you will have variations. (ie. create a form, dispose it, and recreate it).
But this is theoretically, meaning that Microsoft may do whatever wishes with all the resources.
-- modified at 14:21 Sunday 5th March, 2006
It proves that actualy a handle may change in the lifetime of a form. Quoting MSDN[^]:
IWin32Window.Handle Property
Remarks
Depending on the implementer, the value of the Handle property could change during the life of the window.
-- modified at 15:01 Sunday 5th March, 2006
It proves that I was kind of right... Here are some other usefull infos about the way a handle can change : MSDN Link[^]
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Thanks for the reply. That was my understanding of a forms' handle too - a new handle per form instance and it's fixed. But for some strange reason this form gets two during form load (during and after).
If i subcribe to the Handle created and destroyed event its illustrated. I do have some old ActiveX interop controls on the form perhaps they are responsible, also the form becomes an MDI child. However i was just wondering whether there was some kind of common reason why this would occur. I am pretty certain the MDI aspect isn't the issue.
I'll have a read of the MSN resource - will let you know if i get to the bottom of it.
Thanks again
Aj
|
|
|
|
|