[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

How know if code has access to windows resource and vice versa?

Posted on 2008-01-25
5
Medium Priority
?
215 Views
Last Modified: 2013-11-26
Using .NEt 2.0, VS 2005, Windows Forms, VB.Net

How do you know if your VB.Net code has access to a windows resource (such as a printer from the code below). Lately we have been getting system. accessViolationException errors but they are not consistent. Is there a way in .NET to check ?

Thanks
strDefaultPrinter = prtdoc.PrinterSettings.PrinterName
            
            For Each strPrinter In PrinterSettings.InstalledPrinters
                If strPrinter = strDefaultPrinter Then
                    prtExists = True
                End If
            Next strPrinter

Open in new window

0
Comment
Question by:Sanmarie
  • 3
  • 2
5 Comments
 
LVL 14

Accepted Solution

by:
jake072 earned 1500 total points
ID: 20799749
Sanmarie,

I'm not sure why you're getting the error, but I do similar checking in my own code (as to what you have posted).  When you actually print to the printer, the best thing to do is trap it in a Try...Catch loop, and either inform the user, or just try looping through it until the print succeeds.

I don't know anyway of checking for access violations, sorry - not to say that there isn't one, I just don't know of one :)

Jake
0
 

Author Comment

by:Sanmarie
ID: 20800138

Thanks Jake.  The funny thing is that this error is sporadic. The users will report the error and when we check with them again, they say that the printing was successful the second time. I will look into looping until the printing is successful though.

Thanks

San
0
 
LVL 14

Expert Comment

by:jake072
ID: 20800169
San,

I've had similar weird errors myself.  My favorite of late is that none of my Crystal Reports will print to only 1 network printer, while still printing to any OTHER network printer on the network when I have my code in My Documents.  If I move the code out to C:\, it all works fine.

Who knows?? :)

Jake
0
 

Author Comment

by:Sanmarie
ID: 20800219

Sooner or later, we'll find out.
0
 

Author Closing Comment

by:Sanmarie
ID: 31425141
Haven't found the answer but just want to close the queston
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month7 days, 19 hours left to enroll

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question