-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto-pushed to github pauldambra/blog_source@51fe04c
- Loading branch information
Github Actions CI
committed
Jul 24, 2023
0 parents
commit 7a83f74
Showing
718 changed files
with
69,181 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,319 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
|
||
<link rel="manifest" href="/manifest.json" /> | ||
<link rel="icon" href="/images/icons/icon-152x152.png" /> | ||
<!-- theme-color defines the top bar color--> | ||
<meta name="theme-color" content="#575757" /> | ||
<meta | ||
http-equiv="X-Content-Security-Policy" | ||
content="default-src 'self'; script-src 'report-sample' 'self' https://app.posthog.com/static/array.js https://www.googletagmanager.com/gtag/js; style-src 'report-sample' 'self' https://fonts.googleapis.com; object-src 'none'; base-uri 'self'; connect-src 'self' https://app.posthog.com; font-src 'self'; frame-src 'self'; img-src 'self'; manifest-src 'self'; media-src 'self'; report-uri https://pauldambra.report-uri.com/r/d/csp/enforce; worker-src 'self';" | ||
/> | ||
<!-- Add to home screen for Safari on iOS--> | ||
<meta name="apple-mobile-web-app-capable" content="yes" /> | ||
<meta name="apple-mobile-web-app-status-bar-style" content="default" /> | ||
<meta name="apple-mobile-web-app-title" content="MiRaNo" /> | ||
<link rel="apple-touch-icon" href="/images/icons/icon-152x152.png" /> | ||
|
||
<!-- Add to home screen for Windows--> | ||
<meta | ||
name="msapplication-TileImage" | ||
content="/images/icons/icon-152x152.png" | ||
/> | ||
<meta name="msapplication-TileColor" content="#575757" /> | ||
|
||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> | ||
<title>Anonymous methods when invoking in VB net</title> | ||
<link rel="canonical" href="https://pauldambra.dev/2009/05/anonymous-methods-when-invoking-in-vb.html" /> | ||
<meta property="og:url" content="https://pauldambra.dev/2009/05/anonymous-methods-when-invoking-in-vb.html" /> | ||
<meta property="og:type" content="article" /> | ||
<meta property="og:title" content="Anonymous methods when invoking in VB net" /> | ||
<meta | ||
property="og:description" | ||
content="a blog about software engineering" | ||
/> | ||
<meta | ||
property="og:image" | ||
content="https://pauldambra.dev/images/cardboard.jpg" | ||
/> | ||
<meta name="twitter:creator" content="@pauldambra" /> | ||
<meta property="fb:app_id" content="1029758320473951" /> | ||
|
||
<meta name="viewport" content="width=device-width" /> | ||
<meta | ||
name="description" | ||
content="a blog about software engineering" | ||
/> | ||
<meta property="fb:pages" content="1029758320473951" /> | ||
<link | ||
rel="alternate" | ||
type="application/rss+xml" | ||
title="Mindless Rambling Nonsense" | ||
href="https://pauldambra.dev/feed.xml" | ||
/> | ||
<link rel="shortcut icon" href="/favicon.ico" /> | ||
|
||
<link rel="prefetch" href="/images/cardboard.jpg" /> | ||
|
||
<link rel="stylesheet" href="/assets/css/main.css"> | ||
<link rel="stylesheet" href="/assets/css/syntax.css"> | ||
<meta name="msvalidate.01" content="54691C3C7B863CEE60F0305D6EDFF7A8" /> | ||
<meta | ||
name="google-site-verification" | ||
content="hLKEdujpXNQ9PSZWEcQkwxCgL2z1tWxVedeaUmttH7c" | ||
/> | ||
<script> | ||
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]); | ||
posthog.init('phc_DumQNjXoXRQpyaus5OM861c3BEYtwwKyzVTNmPs1XIt',{ | ||
api_host:'https://app.posthog.com', | ||
_capture_performance: true, | ||
autocapture: true, | ||
capture_pageview: true, | ||
disable_session_recording: false, | ||
"opt_in_site_apps": true | ||
}) | ||
</script> | ||
|
||
</head> | ||
<body class="flex flex-col h-screen"> | ||
<header class="flex flex-col px-8 pt-4 text-white text-xl" role="banner"> | ||
<div class="flex flex-col sm:flex-row"> | ||
<div class="no-underline hover:underline"> | ||
<a href="/">Mindless Rambling Nonsense</a> | ||
</div> | ||
<div class="flex-grow my-2 sm:m-0"></div> | ||
<div class="flex justify-start items-end flex-col text-sm"> | ||
<div class="flex items-center"> | ||
<div class="mr-4">Paul D'Ambra</div> | ||
<a href="https://github.com/pauldambra" rel="noopener"> | ||
<img | ||
src="/images/GitHub-Mark-Light-32px.png" | ||
alt="pauldambra on github" | ||
width="32" | ||
height="32" | ||
/> | ||
</a> | ||
</div> | ||
<div class="flex items-center"> | ||
<div class="mr-4">Fangler</div> | ||
<a href="https://twitter.com/pauldambra" rel="noopener"> | ||
<img | ||
src="/images/twitter-32.png" | ||
alt="pauldambra on twitter" | ||
width="32" | ||
height="32" | ||
/> | ||
</a> | ||
</div> | ||
<div class="flex items-center"> | ||
<div class="mr-4"></div> | ||
<a rel="me" href="https://mastodon.me.uk/@pauldambra"> | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="flex-grow"></div> | ||
<div | ||
class="flex align-middle items-start px-2 py-4 text-white space-x-4 text-lg" | ||
> | ||
<nav role="navigation"> | ||
<a class="underline" href="/">Blog Posts</a> | ||
<a class="underline ml-5" href="/weeknotes.html">Week Notes</a> | ||
<a class="underline ml-5" href="/kids-games.html">Kids games</a> | ||
</nav> | ||
</div> | ||
</header> | ||
|
||
<main role="main" class="bg-white p-4 w-11/12 m-auto flex-auto flex-grow"> | ||
|
||
|
||
<script type="application/ld+json"> | ||
{ | ||
"@context":"http://schema.org", | ||
"@type":"BlogPosting", | ||
"headline":"Anonymous methods when invoking in VB net", | ||
"genre":"", | ||
"keywords":"", | ||
"wordCount":"222", | ||
"url":"https://pauldambra.dev/2009/05/anonymous-methods-when-invoking-in-vb.html", | ||
"datePublished":"2009-05-28", | ||
"author":{ | ||
"@type":"Person", | ||
"name":"Paul D'Ambra", | ||
"sameAs":[ | ||
"https://twitter.com/pauldambra", | ||
"https://github.com/pauldambra", | ||
"https://plus.google.com/u/0/+PaulDAmbraPlus" | ||
] | ||
}, | ||
"publisher":{ | ||
"@type": "Organization", | ||
"name": "Paul D'Ambra", | ||
"sameAs": [ | ||
"https://twitter.com/pauldambra", | ||
"https://github.com/pauldambra", | ||
"https://plus.google.com/u/0/+PaulDAmbraPlus" | ||
], | ||
"logo": { | ||
"@type": "ImageObject", | ||
"contentUrl": "https://pauldambra.dev/images/logo.png", | ||
"url": "https://pauldambra.dev" | ||
} | ||
}, | ||
"image":{ | ||
"@type":"ImageObject", | ||
"contentUrl":"https://pauldambra.dev/images/cardboard.jpg", | ||
"url":"https://pauldambra.dev", | ||
"height":"450", | ||
"width":"1000" | ||
}, | ||
"mainEntityOfPage":{ | ||
"@type":"WebPage", | ||
"@id":"https://pauldambra.dev/2009/05/anonymous-methods-when-invoking-in-vb.html" | ||
}, | ||
"articleBody":"Well maybe not but you can get close in some circumstances.\n\n\n\nI've got a situation where when a timer ticks I want to change the background colour of a textbox on a windows form. Since I don't need to pass in any parameters if I was using c# I could use Control.Invoke and an anonymous method… especially since I know I'll always be accessing this control in this method from a different thread.\n\nBut VB .Net doesn't support anonymous methods. Now I've seen all kinds of verbose ways around this on the web… google it - I dare you.\n\nBut if you use Action as below you're pretty close to hardly any extra code…\n\nPublic Sub removeHighlight() Handles timer.Elapsed\n timer.Stop()\n\tIf txtSingleCheck.InvokeRequired Then\n\t\ttxtSingleCheck.Invoke(New Action(AddressOf removeHighlight))\n\tElse\n\t\ttxtSingleCheck.BackColor = Color.White\n\tEnd If\nEnd Sub\n\n\nSo long as the delegate or action you are calling has the same signature as the method you're calling it in then you call InvokeRequired on the control in question and if true you call a new action with the AddressOf the method you're in otherwise you do what you wanted to do but on the appropriate thread.\n\nBot as powerful as anonymous methods I'll grant you but in situations like this it isn't that far removed… is it?\n" | ||
} | ||
</script> | ||
|
||
<article> | ||
<header class="flex flex-col border-b-black border-b-2 bg-white text-black"> | ||
<div class="heading"> | ||
<div class="date">Thu May 28 2009</div> | ||
<h1 class="title leading-10 pt-2 mb-0 mt-1">Anonymous methods when invoking in VB net</h1> | ||
</div> | ||
<div class="meta flex-grow flex flex-row"> | ||
<div class="share-this flex self-end space-x-2"> | ||
<a | ||
id="facebook-share-link" | ||
class="social-share" | ||
target="_blank" | ||
rel="noopener" | ||
href="https://www.facebook.com/dialog/share?app_id=305449093152216&href=https://pauldambra.dev/2009/05/anonymous-methods-when-invoking-in-vb.html" | ||
> | ||
<img | ||
class="w-8" | ||
src="/images/facebook-black-32.png" | ||
alt="share on facebook" | ||
width="32" | ||
height="32" | ||
/> | ||
</a> | ||
<a | ||
id="twitter-share-link" | ||
class="social-share" | ||
target="_blank" | ||
rel="noopener" | ||
href="https://twitter.com/intent/tweet?text=Anonymous+methods+when+invoking+in+VB+net&via=pauldambra&url=https://pauldambra.dev/2009/05/anonymous-methods-when-invoking-in-vb.html" | ||
> | ||
<img | ||
class="w-8" | ||
src="/images/twitter-black-32.png" | ||
alt="share on twitter" | ||
width="32" | ||
height="32" | ||
/> | ||
</a> | ||
</div> | ||
<div class="more-like-this text-right content-end flex-grow"> | ||
<a | ||
class="post-metadata" | ||
href="/categories.html#programming" | ||
> | ||
in: programming | ||
</a> | ||
<div> | ||
<span class="text-slate-500"> | ||
<img class="w-6 h-6 inline-block" src="/images/tag.svg" alt="tag-icon" /> | ||
<a class="no-underline hover:underline" href="/tags.html#vb-net"> | ||
vb.net | ||
</a> | ||
</span> | ||
|
||
<span class="text-slate-500"> | ||
<img class="w-6 h-6 inline-block" src="/images/tag.svg" alt="tag-icon" /> | ||
<a class="no-underline hover:underline" href="/tags.html#code"> | ||
code | ||
</a> | ||
</span> | ||
|
||
</div> | ||
</div> | ||
</div> | ||
</header> | ||
|
||
<div class="post"> | ||
<p>Well maybe not but you can get close in some circumstances.</p> | ||
|
||
<!--more--> | ||
|
||
<p>I've got a situation where when a timer ticks I want to change the background colour of a textbox on a windows form. Since I don't need to pass in any parameters if I was using c# I could use <code class="language-plaintext highlighter-rouge">Control.Invoke</code> and an anonymous method… especially since I know I'll always be accessing this control in this method from a different thread.</p> | ||
|
||
<p>But VB .Net doesn't support anonymous methods. Now I've seen all kinds of verbose ways around this on the web… google it - I dare you.</p> | ||
|
||
<p>But if you use Action as below you're pretty close to hardly any extra code…</p> | ||
|
||
<pre><code class="language-vbnet">Public Sub removeHighlight() Handles timer.Elapsed | ||
timer.Stop() | ||
If txtSingleCheck.InvokeRequired Then | ||
txtSingleCheck.Invoke(New Action(AddressOf removeHighlight)) | ||
Else | ||
txtSingleCheck.BackColor = Color.White | ||
End If | ||
End Sub | ||
</code></pre> | ||
|
||
<p>So long as the delegate or action you are calling has the same signature as the method you're calling it in then you call <code class="language-plaintext highlighter-rouge">InvokeRequired</code> on the control in question and if true you call a new action with the <code class="language-plaintext highlighter-rouge">AddressOf</code> the method you're in otherwise you do what you wanted to do but on the appropriate thread.</p> | ||
|
||
<p>Bot as powerful as anonymous methods I'll grant you but in situations like this it isn't that far removed… is it?</p> | ||
|
||
</div> | ||
<div class="mt-8"> | ||
|
||
<h1>More like this...</h1> | ||
|
||
<div class="grid grid-cols-3 gap-4"></div> | ||
|
||
</div> | ||
|
||
</article> | ||
</main> | ||
<footer class="w-full h-4 bg-black text-white py-8 px-4"> | ||
<a class="no-underline text-white" href="https://pauldambra.dev/feed.xml"> | ||
<img class="inline w-6 h-6" src="/images/rss.svg" alt="the rss feed" /> | ||
<span>Subscribe to RSS feed</span> | ||
</a> | ||
</footer> | ||
|
||
<script> | ||
var tsl = document.getElementById("twitter-share-link"); | ||
tsl.addEventListener("click", function () { | ||
ga("send", { | ||
hitType: "social", | ||
socialNetwork: "twitter", | ||
socialAction: "tweet", | ||
socialTarget: "https://pauldambra.dev/2009/05/anonymous-methods-when-invoking-in-vb.html", | ||
}); | ||
}); | ||
|
||
var fsl = document.getElementById("facebook-share-link"); | ||
fsl.addEventListener("click", function () { | ||
ga("send", { | ||
hitType: "social", | ||
socialNetwork: "facebook", | ||
socialAction: "share", | ||
socialTarget: "https://pauldambra.dev/2009/05/anonymous-methods-when-invoking-in-vb.html", | ||
}); | ||
}); | ||
</script> | ||
|
||
|
||
<script defer src="/register-service-worker.js"></script> | ||
|
||
<link | ||
href="https://fonts.googleapis.com/css?family=Khula&display=swap" | ||
rel="stylesheet" | ||
/> | ||
</body> | ||
</html> |
Oops, something went wrong.