Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8080375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:23:36+00:00 2026-06-05T16:23:36+00:00

I always seen on SyncLock examples people using Private Lock1 As New Object ‘

  • 0

I always seen on SyncLock examples people using

    Private Lock1 As New Object ' declaration
    SyncLock Lock1 ' usage

but why?
In my specific case I’m locking a Queue to avoid problems on mult-threading Enqueueing and Dequeueing my data.

Can I lock the Queue object itself, like this?

    Private cmdQueue As New Queue(Of QueueItem) ' declaration
    SyncLock cmdQueue ' usage

Any help appreciated.
Thanks.

edit:

thanks for all the answers, but tcarvin answer was what I was looking for.
The queue is private from my singleton Comms object that queues new messages to be sent (exposed by a Send method), the queue is consumed in a worker thread within this object one message at a time and the only code I have inside the locks are one call to Enqueue and Dequeue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:23:38+00:00Added an answer on June 5, 2026 at 4:23 pm

    Sage advice from the other posters for sure. But the answer is Yes, you can use the Queue object to lock on. You can use any object. And in your code snippet you declared your queue instance private so you are likely to avoid th common issue of someone else locking on your queue object (assuming you don’t pass the object outside your class). Best-practices though suggest using a dedicated object such that, down the road, someone doesn’t change your code and then expose that queue object being used for locking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've seen examples for load() and ready() , but they always seem to apply
I've seen some examples of ASP.NET MVC3 Scaffolding but those are always simple basic
I have seen source codes always having a typedef for a structure and using
I have always seen the keywords async used in Silverlight but was wondering if
I have always seen people write class.h #ifndef CLASS_H #define CLASS_H //blah blah blah
For example, I've always seen methods referred to as String#split , but never String.split
I've always been curious about audio conversion software, but I have never seen a
Why do constants in all examples I've seen always start with k? And should
I have seen that while installing new software in Linux, I always have to
I've always created arrays by just populating them $foo[] = 'car'; but I've seen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.