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

  • Home
  • SEARCH
  • 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 4060726
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:22:30+00:00 2026-05-20T15:22:30+00:00

This is what I have now: SetText is a Method of the Extended Toolkit

  • 0

This is what I have now:

SetText is a Method of the Extended Toolkit RichTextbox in WPF

public void SetText(FlowDocument document, string text)
{   
    Action<FlowDocument,string> action = SetUIText;
    Dispatcher.CurrentDispatcher.BeginInvoke(action,DispatcherPriority.Background, document, text);
}

private void SetUIText(FlowDocument doc, string text)
{
    TextRange tr = new TextRange(doc.ContentStart, doc.ContentEnd);
    using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(text)))
    {
        tr.Load(ms, DataFormats.Rtf);
    }
}

I do not want to make an extra SetUIText method just to assign it to the delegate for the dispatcher.

So I introduced the lambda expression:

public void SetText(FlowDocument document, string text)
{
    Action<FlowDocument, string> action;

    action = ( doc, txt) =>
    {
        TextRange tr = new TextRange(document.ContentStart, document.ContentEnd);
        using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(text)))
        {
            tr.Load(ms, DataFormats.Rtf);
        }
    };

    Dispatcher.CurrentDispatcher.BeginInvoke(action,DispatcherPriority.Background, document, text);
}

Just check the doc,txt parameter of the lambda. Both parameters are NOT used. What I use instead is document and text inside the lambda expression.

I could use doc OR document AND txt OR text. Is this lambda expression worth at all to use it? Should I stick with my first 2 methods?

  • 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-05-20T15:22:31+00:00Added an answer on May 20, 2026 at 3:22 pm

    I agree with CodeInChaos’s comment: Why are you bothering with an action taking two parameters? I would use this:

    public void SetText(FlowDocument document, string text)
    {
        Action action = () =>
        {
            TextRange tr = new TextRange(document.ContentStart,
                                                  document.ContentEnd);
            using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(text)))
            {
                tr.Load(ms, DataFormats.Rtf);
            }
        };
    
        Dispatcher.CurrentDispatcher.BeginInvoke(action,
                                                 DispatcherPriority.Background);
    }
    

    Note that you can do the same with an anonymous method, which may even look more natural, as you can avoid even writing an empty parameter list:

    Action action = delegate
    {
        TextRange tr = new TextRange(document.ContentStart,
                                              document.ContentEnd);
        using (MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(text)))
        {
            tr.Load(ms, DataFormats.Rtf);
        }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this: Dim myTemp As String myTemp = System.DateTime.Now().ToString(MMMddyyyy_HHmmss) & .pdf System.IO.File.Copy(myFile, c:\
So what I have right now is something like this: PropertyInfo[] info = obj.GetType().GetProperties(BindingFlags.Public);
What I have now (which successfully loads the plug-in) is this: Assembly myDLL =
Now I have seen this question in another forum but it didn't had an
Following on from this question I now have code that can attach to a
So I have this regex: (^(\s+)?(?P<NAME>(\w)(\d{7}))((01f\.foo)|(\.bar|\.goo\.moo\.roo))$|(^(\s+)?(?P<NAME2>R1_\d{6}_\d{6}_)((01f\.foo)|(\.bar|\.goo\.moo\.roo))$)) Now if I try and do a match
I've always wondered about this ... and thankfully, now have a good environment of
This is a continuation question from a previous question I have asked I now
I came across this recently, up until now I have been happily overriding the
I'm at wits end now, I have googled this to death and found nothing.

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.