Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
AnswerRe: Sending byte to comport Pin
Richard MacCutchan19-Mar-18 9:38
mveRichard MacCutchan19-Mar-18 9:38 
QuestionHow to build a PDF maker program at C# Pin
User 1367511418-Mar-18 5:44
User 1367511418-Mar-18 5:44 
AnswerRe: How to build a PDF maker program at C# Pin
Richard MacCutchan18-Mar-18 5:48
mveRichard MacCutchan18-Mar-18 5:48 
AnswerRe: How to build a PDF maker program at C# Pin
Gerry Schmitz18-Mar-18 8:01
mveGerry Schmitz18-Mar-18 8:01 
GeneralRe: How to build a PDF maker program at C# Pin
User 1367511419-Mar-18 0:19
User 1367511419-Mar-18 0:19 
GeneralRe: How to build a PDF maker program at C# Pin
Gerry Schmitz19-Mar-18 6:49
mveGerry Schmitz19-Mar-18 6:49 
GeneralRe: How to build a PDF maker program at C# Pin
User 1367511424-Mar-18 2:19
User 1367511424-Mar-18 2:19 
QuestionAzure Service Bus Messaging - passing messages to UI Pin
Solo118-Mar-18 1:56
Solo118-Mar-18 1:56 
Please can anyone help with a project I'm working on. I'm trying to create a way of running an Azure message queue receiver in a permanently running background thread which immediately updates controls on a WPF page when a new message comes in. I've been playing with examples found on the web which download messages and display them in a console window but I'm struggling to work out how to pass the received messages over to a textbox control on an WPF page.

This is what I have been playing with which seems to work perfectly.....

namespace AzureMessagingReceiver
{
    using System;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using Microsoft.Azure.ServiceBus;

    class Program
    {
        // Connection String for the namespace can be obtained from the Azure portal under the 
        // 'Shared Access policies' section.
        const string ServiceBusConnectionString = "######.......";
        const string QueueName = "#####......";
        static IQueueClient queueClient;

        static void Main(string[] args)
        {
            MainAsync().GetAwaiter().GetResult();
        }

        static async Task MainAsync()
        {
            queueClient = new QueueClient(ServiceBusConnectionString, QueueName);

            Console.WriteLine("======================================================");
            Console.WriteLine("Press ENTER key to exit after receiving all the messages.");
            Console.WriteLine("======================================================");

            // Register QueueClient's MessageHandler and receive messages in a loop
            RegisterOnMessageHandlerAndReceiveMessages();

            Console.ReadKey();

            await queueClient.CloseAsync();
        }

        static void RegisterOnMessageHandlerAndReceiveMessages()
        {
            // Configure the MessageHandler Options in terms of exception handling, number of concurrent messages to deliver etc.
            var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandler)
            {
                // Maximum number of Concurrent calls to the callback `ProcessMessagesAsync`, set to 1 for simplicity.
                // Set it according to how many messages the application wants to process in parallel.
                MaxConcurrentCalls = 1,

                // Indicates whether MessagePump should automatically complete the messages after returning from User Callback.
                // False below indicates the Complete will be handled by the User Callback as in `ProcessMessagesAsync` below.
                AutoComplete = false
            };

            // Register the function that will process messages
            queueClient.RegisterMessageHandler(ProcessMessagesAsync, messageHandlerOptions);
        }

        static async Task ProcessMessagesAsync(Message message, CancellationToken token)
        {
            // Process the message
            Console.WriteLine($"Received message: SequenceNumber:{message.SystemProperties.SequenceNumber} Body:{Encoding.UTF8.GetString(message.Body)}");

            // Complete the message so that it is not received again.
            // This can be done only if the queueClient is created in ReceiveMode.PeekLock mode (which is default).
            await queueClient.CompleteAsync(message.SystemProperties.LockToken);

            // Note: Use the cancellationToken passed as necessary to determine if the queueClient has already been closed.
            // If queueClient has already been Closed, you may chose to not call CompleteAsync() or AbandonAsync() etc. calls 
            // to avoid unnecessary exceptions.
        }

        static Task ExceptionReceivedHandler(ExceptionReceivedEventArgs exceptionReceivedEventArgs)
        {
            Console.WriteLine($"Message handler encountered an exception {exceptionReceivedEventArgs.Exception}.");
            var context = exceptionReceivedEventArgs.ExceptionReceivedContext;
            Console.WriteLine("Exception context for troubleshooting:");
            Console.WriteLine($"- Endpoint: {context.Endpoint}");
            Console.WriteLine($"- Entity Path: {context.EntityPath}");
            Console.WriteLine($"- Executing Action: {context.Action}");
            return Task.CompletedTask;
        }
    }

}


.....just need help with how to turn this into what I need.

Any assistance greatly appreciated!
AnswerRe: Azure Service Bus Messaging - passing messages to UI Pin
Pete O'Hanlon18-Mar-18 2:52
mvePete O'Hanlon18-Mar-18 2:52 
AnswerRe: Azure Service Bus Messaging - passing messages to UI Pin
Gerry Schmitz18-Mar-18 8:12
mveGerry Schmitz18-Mar-18 8:12 
QuestionDifferent behaviors for toggleClass and hasClass Pin
VK1915-Mar-18 3:31
VK1915-Mar-18 3:31 
AnswerRe: Different behaviors for toggleClass and hasClass Pin
Pete O'Hanlon15-Mar-18 4:05
mvePete O'Hanlon15-Mar-18 4:05 
GeneralRe: Different behaviors for toggleClass and hasClass Pin
VK1915-Mar-18 4:30
VK1915-Mar-18 4:30 
AnswerRe: Different behaviors for toggleClass and hasClass Pin
Gerry Schmitz15-Mar-18 6:19
mveGerry Schmitz15-Mar-18 6:19 
GeneralRe: Different behaviors for toggleClass and hasClass Pin
Eddy Vluggen15-Mar-18 11:00
professionalEddy Vluggen15-Mar-18 11:00 
QuestionWhile converting XML to JSON using c#, By providing the data within the class,I’m getting the output.I need to fetch data from file present in folder .Could anyone please help me on this Pin
Member 1372663914-Mar-18 9:37
Member 1372663914-Mar-18 9:37 
AnswerRe: Load XmlDocument from file Pin
Richard Deeming14-Mar-18 10:14
mveRichard Deeming14-Mar-18 10:14 
AnswerRe: While converting XML to JSON using c#... Pin
Dave Kreskowiak14-Mar-18 10:18
mveDave Kreskowiak14-Mar-18 10:18 
Questionwant to know how can i access a list from another class Pin
Member 1372660714-Mar-18 9:15
Member 1372660714-Mar-18 9:15 
AnswerRe: want to know how can i access a list from another class Pin
Dave Kreskowiak14-Mar-18 10:12
mveDave Kreskowiak14-Mar-18 10:12 
AnswerRe: want to know how can i access a list from another class Pin
#realJSOP15-Mar-18 5:56
mve#realJSOP15-Mar-18 5:56 
QuestionC# CA1060 P/Invoke method Pin
Member 1371048711-Mar-18 17:15
Member 1371048711-Mar-18 17:15 
AnswerRe: C# CA1060 P/Invoke method Pin
Pete O'Hanlon11-Mar-18 22:16
mvePete O'Hanlon11-Mar-18 22:16 
GeneralRe: C# CA1060 P/Invoke method Pin
OriginalGriff11-Mar-18 22:34
mveOriginalGriff11-Mar-18 22:34 
GeneralRe: C# CA1060 P/Invoke method Pin
Pete O'Hanlon11-Mar-18 22:52
mvePete O'Hanlon11-Mar-18 22:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.