|
|
I was hoping other developers could give me some advice as to where to store my data! Previously I have always used classes to maintain information relating to the current process. If a background thread required additional information to process, I usually either passed the information in as a parameter or added properties to my thread class.
Recently I have become aware of CallContext and Thread.SetData. I am sure there are also other "places" that .Net provides for storing information relating to the current process/thread.
My question really is: could someone help me understand the scope and purpose of the different storage mechanisms provided by .Net and why you would use one over the other.
Thanks in advance.
-------------------------------------------------------------------
After some investigation, this is my understanding:
CallContext is visible to all theads where Thread data is only visible to the active thread.
I believe these mechanisms are available as a convenient way to gain access to objects and can be used to avoid the difficulties of making classes visible to eachother. I tend to use Class (static) level objects for this, but I can see in some cases (e.g., usertokens) CallContext would be useful.
- Jeff
|
|
|
|
|
AFAIK, Thread.SetData can be used to store data that you are sure you don't want to share among threads.
Regards
Senthil
My Blog
|
|
|
|
|
Hi all,
I p/Invoke a VC++ dll in C#, but there is serious memory leak, how can I fix the memory leakage by the VC++ dll caused by P/Invoke ?
(the leakage seem not come from the internal C++ code inside the dll, so I suspect it come from the loading and unloading of the dll in C#)
Thanks
|
|
|
|
|
Hi!
If it were like you say everybody would have serious problems using P/invoke.
I think it's very unlikely for the P/invoke mechanism to create memory leaks the dll itself doesn't.
The first time you call a p/invoke function, the containing DLL is loaded and as soon as the class you declared the function in goes out of scope (usually when unloading the AppDomain), the DLL is released.
What exactly are the signatures of your functions and your DllImport declarations?
mav
|
|
|
|
|
Hi All,
I am new to C# programming and need ur help.
How can I view or get an HTML page in my windows forms using C# programming. My project does not want to use any Components or ActiveX controls to achieve this.
Keep Smiling
Thanks & regards,
Neerudi
|
|
|
|
|
Whatever I understood it,Giving u code I think it might help you. If some variable is not initialized just initialize it.
public StreamReader viewofhtml()
{
sURL = this.txthttp.Text;
WebRequest wrGETURL;
wrGETURL = WebRequest.Create(sURL);
WebProxy myProxy = new WebProxy("myproxy",80);
myProxy.BypassProxyOnLocal = true;
wrGETURL.Proxy = WebProxy.GetDefaultProxy();
Stream objStream;
objStream = wrGETURL.GetResponse().GetResponseStream();
StreamReader objReader = new StreamReader(objStream);
return objReader;
}
public void btn_server_Click(object sender, System.EventArgs e)
{
if(this.txthttp.Text == "" )
{
MessageBox.Show("Enter the URL with http://www.google.com");
return;
}
StreamReader tempreader=viewofhtml();
string sLine="";
int i = 0;
while (sLine!=null)
{
i++;
sLine = tempreader.ReadLine();
if (sLine!=null)
{
output +=sLine.ToString();
//this.richTextBox1.Text=output;
}
}
this.txtdisplay.Text=output;
}
|
|
|
|
|
I'm in a quandry, I know what an Attribute is, how to use them, and how to make them. But... i still can't seem to find them in the .net framework without spending hours trawling through class names, and when i do find one, i then have to figure out where to use it.
Is there an easier way to locate and identify appropriate attributes for a particular target? As it is, i'm pretty lost, and i see a lot of people using attributes for things like say, VS enviroment support, that i only know exist because I have seen them used.
I suppose it doesn't help that all Attributes END with Attribute, rather than start with it.
There is an easier way right? Like, being able to list all attributes for structs?
Cheers
Tris
|
|
|
|
|
Hi,
Here at work we have a module in C++ which takes text out of the database and puts in a Word document which is loaded with a template.
I have to do about the same and I think it's a bad idea meddling with the existing code. (for numerous reasons; it's poorely designed and is half integrated with another program etc...)
Is it hard to create a C# module which would do about the same? It would be used for a demo so nothing fancy. If I have the document as a file, that would be enough to print it I think.
Any ideas were to start looking? (articles? MSDN? Code? Anything)
tnx!
No hurries, no worries.
|
|
|
|
|
I am not so sure, but crystal reports may help you in desinging documents
|
|
|
|
|
hi
i write a web application with c#.
it has some pages and thir controls such as:
validators , datagrid , datalist with template column
and they have thir event handler functions.
the application works correctly on local.
{ my system: [windows 2003 server ]}
but when i upload it to the host server , the events dont work correctly.
------------
site address:http://siteavval.com/WebVDir/MainGrps.aspx
error message for:
javascript:__doPostBack('MainGrpsList$_ctl0$LBGrpShr','')
|
|
|
|
|
I have an xml file that i'm outputing to a textbox. I have a button that is supposed to go to the next node ach time i click it. I know how to output a whole xml file but, i just want to output each node's content with the click of the button.
|
|
|
|
|
You'll have to elaborate. If you're displaying the entire XML text in a TextBox , then how do you "go to the next node"? You're already displaying all nodes in the TextBox .
Parsing XML, in general, is very easy and there's many ways to do it, from reading the whole file into memory using the XML Document Object Model (DOM) to fast forward-only parsing (SAX, or SAX-like behavior). For forward-only behavior, use an XmlTextRead , move to the first child node of the document element (root node), and keep moving to the next sibling node:
using System;
using System.IO;
using System.Xml;
class Test
{
const string xml = @"<?xml version=""1.0""?>
<root>
<child>
<text1>Hello</text1>
<text2>World</text2>
</child>
<child>
<text1>Howdy</text1>
<text2>Earth</text2>
</child>
</root>";
static void Main()
{
using (StringReader sr = new StringReader(xml))
{
XmlTextReader reader = new XmlTextReader(sr);
while (reader.Read())
{
if (reader.Name == "child")
{
Console.WriteLine(reader.ReadOuterXml());
Console.WriteLine("----------");
}
}
}
}
} You could use an XmlDocument to load the whole document into memory and walk the DOM. Again, it really just depends on your requirements.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Does anyone know how to highlight a row of text in a richTextBox control.
|
|
|
|
|
If you look at the member documentation[^] for the RichTextBox class in the .NET Framework SDK, you'll find several properties that begin with Selection* or Selected* . Many of those properties give you several different ways of selecting text based on what you want to do.
Keep in mind that there's not really a row, though. There are paragraphs that are wrapped and "rows" are formed by whatever words fit within the current width of the RichTextBox . The RichTextBox already does this, though, if you click the far left edge of the control. In applications like WordPad (which use the Rich-Edit control, which the RichTextBox class in .NET encapsulates), the margins are set wider so that it's easier to click and select a line. To do the same in your RichTextBox , set its ShowSelectionMargin property to true .
using System;
using System.Drawing;
using System.Windows.Forms;
class Test : Form
{
static void Main()
{
Application.Run(new Test());
}
Test()
{
RichTextBox rt = new RichTextBox();
Controls.Add(rt);
rt.Dock = DockStyle.Fill;
rt.ShowSelectionMargin = true;
Text = "Test";
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi all
I am using Microsoft FlexGrid (Com Component) in a desktop application(.Net). Using Globalization i am displaying Chinese characters. It is displaying in the labels and messages. But when i am trying to display in the MS FlexGrid it is showing "????" Qestion marks. Can any one help me how will I display Chinese characters in Microsoft Flex Grid.
Thank you
arun
Arun Kumar Sabat
Bangalore
India
|
|
|
|
|
Hi,
How do i know whether the files that are added to the project
are added by File reference or project reference ??
Any help will be great.
Saleem
|
|
|
|
|
There's no way to no just from looking for sure. If the file path (in the PropertyGrid) of a reference references a file in the obj\Debug or obj\Release directory, than it's probably a Project reference. If you switch configurations and the reference is still set to obj\Debug or obj\Release (which it was before), then it's very likely it's a File reference. If the path is somewhere outside a Visual Studio project directory then it's probably a File reference.
When in doubt, remove the reference and re-add it appropriately.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello everyone,
I want to make a datagrid which has a column of Checkbox. By using DataGridBoolColumn class, I have done this. But, When my Application starts, the CheckBox Column will be in the checkstate of "Indeterminate". I want it to be "Uncheked". The CheckBox Control has an Attribute of CheckState, but DataGridBoolColumn hasn't this Attribute. How can i do this? Please help me.
A segment of my code:
DataGridTableStyle dgt = new DataGridTableStyle();
dgt.MappingName = "ok";
DataGridTextBoxColumn dgtbc = new DataGridTextBoxColumn();
dgtbc.MappingName = "Name";
dgtbc.HeaderText= "Name";
dgt.GridColumnStyles.Add(dgtbc);
dgtbc = new DataGridTextBoxColumn();
dgtbc.MappingName = "ID";
dgtbc.HeaderText= "ID";
dgt.GridColumnStyles.Add(dgtbc);
DataGridBoolColumn dgbc = new DataGridBoolColumn();
dgbc.MappingName = "Check";
dgbc.HeaderText = "Check";
dgbc.AllowNull = false;
dgbc.FalseValue = false;
dgbc.TrueValue = true;
dgt.GridColumnStyles.Add(dgbc);
this.dataGrid1.TableStyles.Clear();
this.dataGrid1.TableStyles.Add(dgt);
hope for help
|
|
|
|
|
Hi,
Try using System.Boolean DataColumn for the Checkbox column. I think this would do the job for you. Or else, check if you can set the Checkbox to 2 way input mode. Ie., Just True/False. There is a method to do it. I think it is by setting the ObjGridColumnStyle.NullText = ""; Try it, and let me know if it worked.
- Titan
Titan Williams
Sr. Systems Engineer
Indian
|
|
|
|
|
Hi Titan Williams,
The CheckBox Column in my program has been set to bool. In addition, the CheckBox column has only two states true/false by using the property AllowNull = false. But It doesn't work!
I don't find ObjGridColumnStyle class which you said.
Thanks for your reply. Can you have another method?
welspring
hope for help
|
|
|
|
|
Hi,
Try using System.Boolean DataColumn for the Checkbox column. I think this would do the job for you. Or else, check if you can set the Checkbox to 2 way input mode. Ie., Just True/False. There is a method to do it. I think it is by setting the ObjGridColumnStyle.NullText = ""; Try it, and let me know if it worked.
- Titan
Titan Williams
Sr. Systems Engineer
Indian
|
|
|
|
|
You didn't mention if you're binding the DataGrid at this point in your application's lifetime yet. If not, it will be indeterminate since there's no data backing it. If you have bound the DataGrid , then 1) make sure the DataColumn specifies a boolean data type and that you set the TrueValue and FalseValue properties of the DataGridBoolColumn if the defaults aren't sufficient (they are for SQL Server).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
Thanks for your reply! I think you are right for the reason that there are no data in the CheckBox datacolumn of the datatable backgrounded. I have solved the problem by filling data to the datacolumn.
Another problem is, when clicked in the end of the datagrid, a new row will be created. The CheckBox column of the new row will still be in indeterminate state. How to resolve this?
Thanks again.
Welspring
hope for help
|
|
|
|
|
It's in an indeterminate state because there's no actual data row created yet. If you want to default the value, you should either add a DataColumn to your DataSet with the DefaultValue property set, or do this a better way by creating a typed DataSet in the designer, which also facilitates data-bound control design in VS.NET as well as typed access to fields in your code editor. Read Generating a Strongly Typed DataSet[^] in the .NET Framework SDK, as well as ADO.NET Datasets[^] in the Visual Studio .NET product documentation for information about how to create typed DataSet s using the component designer (slick).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|