Category

Uncategorised

Difference between ThreadPool.QueueUserWorkItem() and Task.Run()

ThreadPool.QueueUserWorkItem and Task.Run are both mechanisms provided by .NET for executing code asynchronously on a background thread. However, they have some differences in terms of usage and functionality.

  1. Usage:
    • ThreadPool.QueueUserWorkItem is a lower-level API that allows you to enqueue a method for execution on a thread from the thread pool. It takes a WaitCallback delegate as a parameter, which represents the method to be executed. You can pass data to the method using the state parameter of the QueueUserWorkItem method.
    • Task.Run is a higher-level API introduced in the Task Parallel Library (TPL) and provides a simplified way to schedule work on a thread pool thread. It takes a Func<Task> or Action delegate as a parameter and returns a Task representing the asynchronous operation.
  2. Flexibility:
    • ThreadPool.QueueUserWorkItem provides a basic mechanism for executing simple methods asynchronously. It doesn’t offer advanced features like cancellation, continuations, or support for returning values.
    • Task.Run provides more flexibility and higher-level abstractions. It allows you to easily chain multiple asynchronous operations together, handle exceptions, cancellation, and aggregate results. Tasks can be awaited, and they integrate well with the async/await pattern.
  3. Integration with async/await:
    • ThreadPool.QueueUserWorkItem does not directly support the async/await pattern. If you need to execute an async method using QueueUserWorkItem, you would need to wrap it inside a delegate or lambda expression and manually handle the async operation and its completion.
    • Task.Run is designed to work seamlessly with the async/await pattern. It automatically wraps the provided delegate in a task and allows you to use async/await keywords for clean and straightforward asynchronous code.
  4. Return Values:
    • ThreadPool.QueueUserWorkItem does not have a built-in mechanism for returning values from the executed method. If you need to retrieve a value or propagate an exception, you would need to use other synchronization mechanisms like AsyncWaitHandle, shared variables, or callbacks.
    • Task.Run supports returning values from the executed delegate by using the Task<TResult> variant and specifying the return type of the delegate. It allows you to easily access the result or handle exceptions using the Result property or the await keyword.

In general, if you need a simple mechanism to execute work on a background thread without advanced features, ThreadPool.QueueUserWorkItem can be a suitable choice. On the other hand, if you require more flexibility, integration with async/await, and built-in support for advanced features, Task.Run and the TPL provide a more powerful and convenient way to handle asynchronous operations.

Here’s a small sample that demonstrates the differences between ThreadPool.QueueUserWorkItem and Task.Run:

using System;
using System.Threading;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {
        // Example using ThreadPool.QueueUserWorkItem
        ThreadPool.QueueUserWorkItem(DoWork, "Hello from ThreadPool");

        // Example using Task.Run
        Task.Run(() => DoWorkAsync("Hello from Task.Run"));

        Console.WriteLine("Main thread continues executing...");

        Console.ReadLine();
    }

    static void DoWork(object state)
    {
        string message = (string)state;
        Console.WriteLine(message);
        Thread.Sleep(2000); // Simulate some work
        Console.WriteLine("Work completed on ThreadPool");
    }

    static async Task DoWorkAsync(string message)
    {
        Console.WriteLine(message);
        await Task.Delay(2000); // Simulate some async work
        Console.WriteLine("Work completed on Task.Run");
    }
}

Feel free to run the sample and observe the output to better understand the behavior of ThreadPool.QueueUserWorkItem and Task.Run.

ASP.NET – HttpRequest.Url -Difference between Url.OriginalString and Url.AbsoluteUri

In the context of the HttpRequest.Url property, both Url.OriginalString and Url.AbsoluteUri provide information about the URL of the request. However, there is a subtle difference between the two:

  1. Url.OriginalString: This property returns the original URL string that was used to create the Uri instance. It includes any special characters or percent-encoded representations that might be present in the URL. For example, if the original URL contained spaces, special characters, or non-ASCII characters, OriginalString would preserve them without any modification.
  2. Url.AbsoluteUri: This property returns the absolute URL string, which is the canonical representation of the URL. It represents the normalized form of the URL with all necessary escaping and encoding applied. It ensures that the URL is valid and conforming to the URL specification. The AbsoluteUri property provides a valid and usable URL that can be used for making subsequent requests or resolving the resource.

To summarize, Url.OriginalString gives you the exact original string as it was provided, while Url.AbsoluteUri provides the normalized and escaped URL that can be safely used for further processing or making requests.

Update the email address in Microsoft Office365

It is possible to update the email address of an Office 365 account. Here are the steps you can follow:

  1. Go to the Office 365 admin center and sign in with your admin account.
  2. Click on the “Users” tab in the left-hand menu.
  3. Select the user whose email address you want to update.
  4. Click on the “Edit” button next to the user’s email address.
  5. Enter the new email address in the “Email” field.
  6. Click on “Save” to update the email address.

Please note that changing the email address will also change the user’s login name, so you may need to update any external systems or applications that use the old email address as a username. Additionally, changing the email address may affect any email rules or settings that the user has configured, so you should advise the user to review their email settings after the update.

Block emails from an email in Microsoft Office 365

You can create a mail flow rule to block the sender’s email address in the new Exchange admin center. Here are the steps:

  1. Sign in to the new Exchange admin center at https://admin.exchange.microsoft.com/
  2. Go to Mail flow > Rules
  3. Click + to create a new rule
  4. In the New rule page that opens, enter a name for the rule
  5. Under Apply this rule if, select The sender…
  6. Select is this person and enter the email address of the sender you want to block
  7. Under Do the following, select Block the message
  8. Click Save to save the new rule

Best MongoDB Clients

There are several MongoDB clients available that are user-friendly and easy to use. Here are some of the popular ones:

  1. MongoDB Compass: It is an official graphical user interface (GUI) for MongoDB. It provides a visually appealing interface to manage, explore and query data, create indexes, and more.
  2. Robo 3T: It is a free and open-source MongoDB GUI client. It offers a simple and intuitive interface, supports a wide range of MongoDB features, and is available for Windows, Mac, and Linux.
  3. Studio 3T: It is a paid MongoDB GUI client that offers a rich set of features, including SQL support, data visualization, and a powerful aggregation pipeline editor.
  4. NoSQLBooster for MongoDB: It is a powerful and user-friendly MongoDB GUI client that supports SQL query, import/export data, and auto-completion for queries.
  5. mViewer Pro: It is a lightweight and easy-to-use MongoDB GUI client that allows you to view and edit data in a tree-like structure.

Overall, MongoDB Compass and Robo 3T are among the most user-friendly and easy-to-use MongoDB clients, and they are also available for free.

Should vspscc file be checked into TFS?

Yes, the .vspscc file should be checked in to Visual Studio and TFS (Team Foundation Server). The .vspscc file is a source control file that helps manage the source code in Visual Studio projects. It contains information about the files in the project, such as their source control status, and helps maintain consistency between the local copy of the project and the version stored in the source control repository.

When you check in the .vspscc file, it ensures that the correct source control information is maintained and that the project can be properly managed in TFS. If the .vspscc file is not checked in, it can lead to issues such as incorrect source control status or inconsistencies between the local copy and the version in TFS.

Therefore, it is recommended that you always check in the .vspscc file along with the rest of the project files to ensure proper management of your Visual Studio project in TFS.

How to give view access to a new user in Mandrill

Follow the below steps:

  1. Log in to your Mandrill account.
  2. Click on the “Settings” option from the main menu.
  3. In the “Settings” menu, click on the “Users” option.
  4. Click on the “Add a User” button.
  5. Enter the email address of the new user in the “Email” field.
  6. Select the “Viewer” role from the “Role” dropdown menu.
  7. Choose the permissions you want to grant to the new user under “Permissions.”
  8. Click the “Add User” button to save your changes.

Once you have completed these steps, the new user will receive an email inviting them to create an account and log in to Mandrill. They will then be able to access the account with view-only permissions according to the permissions you granted in step 7.

How many Requests can a Server handle?

Determining the maximum requests a server can handle is a complex task that depends on various factors, such as the server hardware, network infrastructure, server software configuration, and the nature of the requests. Here are some general steps to estimate the maximum requests a server can take:

  1. Check the server specifications: Look at the server specifications such as CPU, RAM, disk space, and network bandwidth. These specifications can give you an idea of the server’s capacity to handle requests.
  2. Check the server logs: Analyze the server logs to determine the number of requests it receives in a given period. This can help you understand the server’s current traffic load and whether it is approaching its limit.
  3. Conduct load testing: Use load testing tools to simulate heavy traffic and measure the server’s response time and resource usage. Gradually increase the number of requests until you notice performance degradation or errors.
  4. Analyze resource usage: Monitor the server’s resource usage during the load test to identify any bottlenecks, such as CPU or memory usage. This can help you determine the maximum number of requests the server can handle before it becomes overwhelmed.
  5. Optimize server software: Adjust server software settings, such as caching, threading, and connection limits, to improve performance and increase the maximum number of requests the server can handle.

Keep in mind that the maximum requests a server can handle is not a fixed number and can change over time as traffic patterns and server configurations change. Therefore, it’s important to regularly monitor and optimize your server’s performance to ensure it can handle your expected traffic.

Video on Demand (VOD) and Video Streaming – How it works!

Video on demand (VOD) and video streaming are two popular methods for delivering video content over the internet. While VOD allows users to download and watch videos on their own time, video streaming enables real-time playback without the need for a download.

Technically, video streaming involves sending compressed video data in small chunks, which are decoded and played by the user’s device in real-time. The most common streaming protocol used today is HTTP Live Streaming (HLS), which segments video into small files called “chunks”.

When a user requests to watch a video, the server divides the video into chunks and sends the data to the user’s device. The device’s media player downloads each chunk and decodes it for playback, while simultaneously downloading the next chunk in the sequence.

HLS files used in video streaming typically include:

  1. Manifest file (M3U8): This is an index file that contains a list of video segments (chunks) that the player requests from the server. It tells the player how to download and play the video.
  2. Video chunks (TS files): These are small video files that contain a portion of the video content. The player downloads these files in sequential order, and decodes them to play the video.
  3. Encryption keys (key files): These are small files that contain the encryption keys used to secure the video content.
  4. Subtitle files: These are text files that contain captions or subtitles for the video.

When a user watches a video on a browser, the media player in the browser sends an HTTP request to the server for the manifest file. The server then sends the manifest file, which the media player reads to determine the location and sequence of the video chunks. The media player then requests the video chunks, which are downloaded and decoded in real-time for playback.

In summary, video streaming involves the segmentation of video into small files called “chunks”, which are sent to the user’s device for real-time playback. The HLS protocol is the most commonly used streaming protocol, and it uses files such as the manifest file, video chunks, encryption keys, and subtitle files to deliver video content over the internet.

PETTIMUDI HILLS (Koompanpara) | Adimali | Munnar | Must Visit tourist Spot in Idukki | 360 Views | Habeeb Vlogs

Hi Friends, How are you doing? Today we are not in Dubai, but God’s own country – Kerala, India.
I am on a short vacation, and set out to explore a hidden beauty in Kerala – Pettimudi Hills, near Munnar. We reached the base of the hill by 6:00 AM and started the hike. Its Jungle alongside. But we walk through tall green grass. Sometimes the grass was even taller than me.
The grass is beautiful yet dangerous. If it comes in close contact with your body its edges can act like a blade, so beware.
During the ascend, the surroundings were covered in thick fog. This fog is the cloud, that we see on hill top, when we look from the bottom of the mountain.
I am at this beautiful place only because of the travel vlogger and explorer – Jomon. He runs a youtube channel exploring all the unexplored, beautiful places in Kerala. Soon, he will set out for an all India trip and do check out his channel; the link is in the description.

The flora and fauna of the place was not exactly as I expected. As we start approaching the hill top, its only grasses around. As fauna, it was only some insects, leeches and birds. No traces of animals. During summers, all these grasses would dry out leaving the hill barren with no greenry. So make sure to visit the place during rainy season.

Around me, its mountains and hills covered in greenery, But, as of now, nothing is visible because of the thick fog. The feeling, is literely like, I’ve woke up from sleep to see myself on top of clouds.
We were lucky that it didn’t rain during our trek. It was heavily raining the previous night. And From Jomon I came to know that, if it rains the previous night, then the next day morning, will have thick fog. So thats what we are experiencing now.
With all the mist and fog, the place was so mysterious and I totally fail to express the experience in words.
O’ thats a large Moth. It reminded me of Harry Potter and Lord of the Rings, as if it came to pass me a message ..

There are 5 hill top points on our way, and each give a beautiful and exclusive view point.

Finally, we have reached the top. What an awesome view; as if we have reached another world. Its a moment we truely admire the creator and reemphasise how tiny creature we human beings are.
The only visitors I came across, were, university students. They visit in groups on their Motor bikes. It was a great opportunity to meet them and get connected. They were really fun, much more than, what, we used to be during our university days. Such an inspiring new generation.
We met some Civil Engineering Students from Mar Athanasius College of Engineering – MACE. It’s one of the prestegious Engineering colleges in Kerala founded in 1961.

On our way back, we stopped at a small water fall. I could see the falls eagerly waiting for the monsoon rains to show its full might…

Driving through Indian Roads especially in the suburbs is an entirely different experience. You will be at the edge of the seat, through out the drive. The same narrow road unilized by a cyclist as well as Large truck, makes it one of the most unique experience. You need to be, vigilant and careful on these roads. But the feel is amazing. Sometimes, You feel like driving through a jungle.

Stay tuned for another vlog. If you like the video, don’t forget to like, Share, Subscribe and press the bell icon.

#pettimudihills #pettimudi #koompanpara #munnar #idukki #trekking #hiking #habeebvlogs #keralagodsowncountry #kerala #keralatourism #keralatouristplaces #alimali #insta360