Pool Values in Memory

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have recently created an Excel UDF (User Defined Function) with .NET. (For details: http://blogs.msdn.com/b/eric_carter/archive/2004/12/01/273127.aspx http://blogs.msdn.com/b/eric_carter/archive/2004/12/01/273127.aspx )
Whenever it is triggered it logs/appends the input text in a text file.
Like:
<img src="http://social.microsoft.com/Forums/getfile/3667/" alt="
And the output is:
<img src="http://social.microsoft.com/Forums/getfile/3668/" alt="
But whenever i trigger this function, it opens the textfile and closes it which is a performance hit over 500 records. So i thought to pool the values in memory. But i have absolutely no idea...
Btw simple code is below:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; using System;
<span style="color:Blue; using System.Runtime.InteropServices;
<span style="color:Blue; using Microsoft.Win32;

<span style="color:Blue; namespace AutomationAddin
{

<span style="color:Green; // Replace the Guid below with your own guid that
<span style="color:Green; // you generate using Create GUID from the Tools menu
[Guid(<span style="color:#A31515; "5268ABE2-9B09-439d-BE97-2EA60E103EF6")]
[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(<span style="color:Blue; true)]
<span style="color:Blue; public <span style="color:Blue; class MyFunctions
{
<span style="color:Blue; public MyFunctions()
{
}

<span style="color:Blue; public <span style="color:Blue; bool MyDOTNETUDF(<span style="color:Blue; string TextToWrite)
{
<span style="color:Green; // 1: Append single line to new file
<span style="color:Blue; using (StreamWriter writer = <span style="color:Blue; new StreamWriter(<span style="color:#A31515; "C:\deneme.txt", <span style="color:Blue; true))
{
writer.WriteLine(TextToWrite);
}

<span style="color:Blue; return <span style="color:Blue; true;
}

[ComRegisterFunctionAttribute]
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; void RegisterFunction(Type type)
{

Registry.ClassesRoot.CreateSubKey(
GetSubKeyName(type, <span style="color:#A31515; "Programmable"));
RegistryKey key = Registry.ClassesRoot.OpenSubKey(
GetSubKeyName(type, <span style="color:#A31515; "InprocServer32"), <span style="color:Blue; true);
key.SetValue(<span style="color:#A31515; "",
System.Environment.SystemDirectory + <span style="color:#A31515; @"mscoree.dll",
RegistryValueKind.String);
}
[ComUnregisterFunctionAttribute]
<span style="color:Blue; public <span style="color:Blue; static <span style="color:Blue; void UnregisterFunction(Type type)
{

Registry.ClassesRoot.DeleteSubKey(
GetSubKeyName(type, <span style="color:#A31515; "Programmable"), <span style="color:Blue; false);
}
<span style="color:Blue; private <span style="color:Blue; static <span style="color:Blue; string GetSubKeyName(Type type,
<span style="color:Blue; string subKeyName)
{
System.Text.StringBuilder s =
<span style="color:Blue; new System.Text.StringBuilder();
s.Append(<span style="color:#A31515; @"CLSID{");
s.Append(type.GUID.ToString().ToUpper());
s.Append(<span style="color:#A31515; @"}");
s.Append(subKeyName);
<span style="color:Blue; return s.ToString();
}
}
}
[/code]
<br/>
<br/>

<hr class="sig Senior BI Consultant & PM @ http://www.nexum.com.tr" style="text-decoration:none
Nexum Bogazici <br/>
<b>If it is, Please dont forget to mark as answered or at least vote as helpful if the post helps you in any ways.</b>
<br/>
http://www.ssisnedir.com/ <img src="http://feeds.feedburner.com/SsisNedir.1.gif" alt="Visit: ssisnedir.com" style="border:0
http://twitter.com/onuromer <img src="http://www.twitterbuttons.com/upload/images/6dc65623fdtwitter-bg-t.png" title="Follow Me" alt="Follow Me" width="40" height="40" style="border:0

View the full article
 

Similar threads

Back
Top