简体   繁体   中英

Open a filled outlook email in vb.net then close thread

So just to be clear, I've got this "working" (aka it's usable). Here's my code:

  Dim Outl As Object
            Outl = CreateObject("Outlook.Application")
            If Outl IsNot Nothing Then
                Dim omsg As Object
                omsg = Outl.CreateItem(0)
                omsg.cc = UserId
                omsg.subject = "CRIT " & eventId & " - " & shortSummary & ""
                omsg.body = reportBody
                omsg.Display(True) 'will display message to user
                EmailExportBackgroundWorker.CancelAsync()
                EmailExportBackgroundWorker.Dispose()
            End If
        End If

This does exactly what I need, except for a couple of nit-picky things. In effect vb.net is treating this like I've opened a dialog window, it's waiting on the user to do something with the popped-up email before moving on. I got around my program hanging during this by moving it to a background worker, but the email that's opened itself has a couple of quirks I'd like to solve.

Mainly, it can't be minimized, the minimize button is grayed out. It's also opened maximized, not the hugest deal, but annoying. Lastly it is listed as unresponsive. It's not, you can finish filling it out and send it, but it shows as unresponsive.

What I would like to do is have the tread open the email, then be done with it! VB.NET has nothing more to do with it once it's open. I just can't find a way, even a hacky one, to do this. In fact, since it's a background thread, I don't even really care if it lets go. I just want the user to be able to minimize the email till they CHOOSE to do something with it. Not be forced to deal with it. You CAN click on another program in the task bar, and send the email to the back, but not all users realize that's possible.

I solved my own issue. Turns out my problems came from this line:

omsg.Display(True)

This causes it to open it as I described. More or less locking up the thread. However:

omsg.Display

fixes all my issues. The original example code I had seen had it like that and I didn't realize you could change it. I don't even think I needed the background worker now, but not changing it.

Anyway, solved. Thanks for looking ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM