|
Hello,
I've tried filling a tree view with a large database on a worker thread (so my main window keeps responding.)
I get an InvalidOperationException saying that I'm doing it from the wrong thread. If I do it from the main thread, it is very slow, and can take up to 30 seconds.
Any ideas? Thanks,
-- LuisR
___________
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
|
|
|
|
|
DISCLAIMER: I've never tried this so I don't know if it will work.
Would you be able to generate the tree structure first and then when your data loading thread is finished it fires an event to tell the main thread it is finished. The event handler then takes the nodes and attaches them to the tree control.
This would mean that for 30 seconds you have an empty tree control - but at least the application is responsive.
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Not getting the response you want from a question asked in an online forum: How to Ask Questions the Smart Way!
|
|
|
|
|
Mmm interesting idea... I'll give it a try! thanks!
During thos 30 seconds, I could fill the tree with a "Populating tree control, please wait..." node.
-- LuisR
___________
Luis Alonso Ramos
Chihuahua, Mexico
www.luisalonsoramos.com
|
|
|
|
|
If you want to modify a control from a thread other than the thread that created it, you should use the Invoke method of the Control (in that case the TreeView) to invoke the function that adds the node to the tree. A simple example for adding a node which takes a string parameter for the node could be:
private void AddNode(string nodeText)<br />
{<br />
myTreeView.Nodes.Add(nodeText);<br />
}
then you can declare a delegate to call this function:
private delegate void AddNodeDelegate(string nodeText);
and then from any thread, you can safely do this:
string nodeText = "This is my safe node text";<br />
AddNodeDelegate myAdd = new AddNodeDelegate(AddNode);<br />
myTreeView.Invoke(myAdd, new object[] { nodeText } );
|
|
|
|
|
I'm making plans to build an application that will be a MDI Host application that loads plugins from a department web server. Does anyone have any examples or advice thaqt they could give on this project?
Thanks
Moebious
|
|
|
|
|
|
Hey all,
Work is really boring so I'm going to write a screen scraper. But the best say to do this is using Regex's, something I need to work on because it's a particular area of weakness. If a page has the following structure:
<html>
<head>
<title>foo</title>
</head>
<body>
<table><tr><td>foo</td></tr></table>
<table><tr><td>foo</td></tr></table>
</body>
</html>
Is there a regex I could use to pick up what's between the tags? Like a regex to grab the title, another for the first table, and the second?
Thanks much
*->>Always working on my game, teach me
*->>something new.
cout << "dav1d\n";
|
|
|
|
|
Sure, here is a quick example so I am sure you can expand on it:
private void ShowContent(string s)
{
Regex r = new Regex("<td>*[a-z]*</td>", RegexOptions.IgnoreCase);
Match m = r.Match(s);
while(m.Success)
{
string val = m.Value.Delete(0, 4).Delete(m.Value.Length - 4, 4);
if(val != null)
Console.WriteLine(v);
m = m.NextMatch();
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
* is not a wildcard, though - you should actually just use "<td>[A-Za-z0-9]*</td>", which means that 0 or more alphanumeric characters (there are excape sequences you can use, too) are allowed between TD elements. What you have now will match 0 or more openning TD elements as well.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Regex can be horribly unreliable and a complete pain when unforeseen formats creep up. I recommend using SgmlReader[^] written by a fellow Microsoftie. HTML is, if you don't know, an SGML grammar, as is XML and XHTML (which is actually an XML grammar that only looks like HTML because it uses the XHTML namespace as the default namespace so that namespace prefices aren't required).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hello,
I want to know, how can i enable/disable internet access to certain systems on the network ?
Is there any class/... for this ?
Regards,
Asim
|
|
|
|
|
Don't cross post acrossed Forums. It's considered very rude...
There is no class to do this. The best way to do it is a Proxy server...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi
i am trying to make a simple web application using web services with c# web matrix
i have get the data from html page and i can print it on my aspx page
but i could not be able to pass my data to my web services
in my web services i want to send my data in access database
we i show you my code as under that i used ...
this is my html code
<html>
<head>
</head>
<body>
<form id="Form1" name="form1" action="aspx1.aspx" method="post">
<p>
</p>
<p>
First Name:<input type="text" name="fname"/>
</p>
<p>
Last Name:<input type="text" name="lname"/>
</p>
<p>
<input type="submit" value="Submit" />
</p>
</form>
</body>
</html>
this is my aspx page code
<%@ Page Language="C#" Debug=true %>
<script runat="server">
void Page_Load(object src,EventArgs e)
{
String fn,ln;
fn = Request.Form.Get("fname");
ln=Request.Form.Get("lname");
Response.Write("Your First Name is = " +"<b>" +fn +"</b>" +"<br>");
Response.Write("Your Last Name is = " +"<b>" +ln +"</b>" +"<br>");
}
</script>
<html>
<head>
</head>
<body>
</body>
</html>
and this is my web services code
<%@ WebService language="C#" Debug="True" class="my" %>
using System;
using System.Web.Services;
using System.Xml.Serialization;
public class my {
[WebMethod]
public void Add(string a, string b) {
OleDbConnection objConnection = null;
OleDbCommand objCmd = null;
string strConnection, strSQL;
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0 ;Data Source="+Server.MapPath(".\\database\\t1.mdb");
// Create and open the connection object
objConnection = new OleDbConnection(strConnection);
objConnection.Open();
// Set the SQL string
strSQL = "INSERT INTO sis (fname, lname) VALUES ( a , b)";
// Create the Command and set its properties
objCmd = new OleDbCommand(strSQL, objConnection);
// here our ionsert query will execute and insertour data in the database.
objCmd.ExecuteNonQuery();
objConnection.Close();
}
}
Mazhar Hussain
|
|
|
|
|
This belongs in the ASP.NET forum.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hello,
how could one get tree folder browser in C#, like the one that Windows Explorer uses? I looked at all examples given, and have made my own version, but I can't get it to display Network Places. I can get the names of the all volumes connected (HDD, CDs, USB disks...), but don't know how to get Network Places.
So if anyone can point me the right way....
thnx,
ajvn
|
|
|
|
|
ajvn wrote:
So if anyone can point me the right way....
Sure, you will need to P/Invoke many of the Win32 functions and structures to do so, the following should get you started.
[DllImport("mpr.dll")]
public static extern int WNetOpenEnum(ResourceScope dwScope, ResourceType dwType, ResourceUsage dwUsage, NETRESOURCE lpNetResource, out IntPtr lphEnum);
[DllImport("mpr.dll")]
public static extern int WNetEnumResource(IntPtr hEnum, ref uint lpcCount, IntPtr lpBuffer, ref uint lpBufferSize);
[DllImport("mpr.dll")]
public static extern int WNetCloseEnum(IntPtr hEnum);
[StructLayout(LayoutKind.Sequential)]
public class NETRESOURCE
{
public ResourceScope dwScope = 0;
public ResourceType dwType = 0;
public ResourceDisplayType dwDisplayType = 0;
public ResourceUsage dwUsage = 0;
public string lpLocalName = null;
public string lpRemoteName = null;
public string lpComment = null;
public string lpProvider = null;
}
public enum ResourceScope
{
RESOURCE_CONNECTED = 1,
RESOURCE_GLOBALNET,
RESOURCE_REMEMBERED,
}
public enum ResourceType
{
RESOURCETYPE_ANY = 0,
RESOURCETYPE_DISK,
RESOURCETYPE_PRINT,
}
public enum ResourceDisplayType
{
RESOURCEDISPLAYTYPE_GENERIC = 0,
RESOURCEDISPLAYTYPE_DOMAIN,
RESOURCEDISPLAYTYPE_SERVER,
RESOURCEDISPLAYTYPE_SHARE,
}
public enum ResourceUsage
{
RESOURCEUSAGE_ALL = 0,
RESOURCEUSAGE_CONNECTABLE,
RESOURCEUSAGE_CONTAINER,
}
public const int NO_ERROR = 0;
public const int ERROR_NO_MORE_ITEMS = 259;
- Nick Parker My Blog | My Articles
|
|
|
|
|
|
Hello
I am trying to use Assembly.Load function to load C# dll from the subdirectory "subdir":
a = Assembly.Load("TestSer.dll");
But it generate an error: Can't find an assembly TestSer.dll
I am using configuration file:
<configuration>
<runtime>
<assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatepath="subdir">
Can anybody help?
Oleg Chebotar
|
|
|
|
|
When you post tags in angled brackets (i.e., HTML or XML), you need to encode them (ex: < == <), or check "Do not treat <'s as HTML tags" below.
You should read Specifying an Assembly's Location[^], as well as How the Runtime Locates Assemblies[^]. The first link discusses how to use the <probing> element to specify the probing path, while the second is a general article discussing how the CLR locates assemblies (and in what order directories are checked).
Also make sure that your .config file is named the same as your application (libraries using the defualt loader do not read from their own .config files - only the AppDomain into which they're loaded) and in the same directory. So, if your application is named myapp.exe, then your configuration file should be named myapp.exe.config and be in the same directory as your application.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thank you for the answere.
Config file is named TestAsm.exe.config (application is TestAsm.exe):
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="testdir"/>
</assemblyBinding>
</runtime>
</configuration>
"testdir" is the subdir of the directory where TestAsm.exe is located.
And one more question - why config file disappear every time I compile the application?
|
|
|
|
|
If you have a file named app.config in your project, this is renamed appropriately and copied to the target directory. If you don't, it may be deleted since target files are deleted when you rebuild. I recommend adding an app.config to our project and specifying your settings in that.
If you're debugging your application from Visual Studio, understand that your application is actually run from the target directory underneath obj, not bin (ex: obj\Debug, not bin\Debug). So, if you're copying your dependent assembly to bin\Debug\testdir, it won't be found if you're running the application - attaching the debugger or not - from Visual Studio. You need to place it in obj\Debug\testdir.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I added TestAsm.exe.config file to the project but it doesn't work. "subdir" is placed both in obj and bin directory. All I get:
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Post-policy reference: TestSer
LOG: Attempting download of new URL file:///C:/SOFT/C#/samples/TestAsm/TestAsm/bin/Debug/TestSer.DLL.
LOG: Attempting download of new URL file:///C:/SOFT/C#/samples/TestAsm/TestAsm/bin/Debug/TestSer/TestSer.DLL.
LOG: Attempting download of new URL file:///C:/SOFT/C#/samples/TestAsm/TestAsm/bin/Debug/TestSer.EXE.
LOG: Attempting download of new URL file:///C:/SOFT/C#/samples/TestAsm/TestAsm/bin/Debug/TestSer/TestSer.EXE.
Thank you
Oleg Chebotar
www.gelosoft.com
|
|
|
|
|
I said you add a file named app.config (exactly that name) to your project, and it will get renamed accordingly. If you run the application using Vs.NET, it runs from obj. If you simply launch your application you typically do it from bin. Whatever is fine so long as the correctly named file (not adding a file named app.config will not move it correctly - actually, not at all) is present in the right directory.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Thanks a lot!
It works.
Oleg Chebotar
www.gelosoft.com
|
|
|
|
|
Heath Stewart wrote:
If you're debugging your application from Visual Studio, understand that your application is actually run from the target directory underneath obj, not bin (ex: obj\Debug, not bin\Debug).
I've always known Visual Studio to run the app from bin\debug. In fact, the debug output clearly states that the .exe is being loaded from the bin\Debug path. Did I misunderstand your statement?
Charlie
if(!curlies){ return; }
|
|
|
|