|
This will help Multithreading in .NET[^]
I will also add that WinForm / WPF, they are both thread unsafe and work on the UI thread (the one started in Program.Main() with a Run() method which act as a Window message pump).
To send message on the UI thread both (WinForm) Control and (WPF) DispatcherObject have a method called BeginInvoke().
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
You surely would be interested in this:
http://www.albahari.com/threading/part4.aspx[^]
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Hi
I having a problem when I create a simple function and I try to pass n parameters
These is the code:
public double TestFunction(params Object[] YourCells)
{
return 0;
}
This is shows on excel and I can use on the Insert Formula, but when Excel interprete is give to me the #VALUE! error
This is the formula on excel cell: =TestFunction(C2,F2)
Shows everything fine.
Can anyone please help me.
Visual Studio 2008, Excel 2007.
Thanks
|
|
|
|
|
Ok, I have never understood this. Its an interface and therefore has no code in it...only 'stubs'. So when you implement it, it generates the Dispose method...and the Dispose method has code in it...how does this work? Id like to have my interface do something like this.
for example, create a class and implement IDisposable, press enter and it will generate the following VARIABLES and code blocks, not just empty subs.
Private disposedValue As Boolean = False ' To detect redundant calls
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
' TODO: free other state (managed objects).
End If
' TODO: free your own state (unmanaged objects).
' TODO: set large fields to null.
End If
Me.disposedValue = True
End Sub
#Region " IDisposable Support "
' This code added by Visual Basic to correctly implement the disposable pattern.
Public Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
--
"Keyboard not found. Press < F1 > to RESUME. "
Source unknown (appears in many common BIOSes as a real error message)
|
|
|
|
|
It's simple. The interface says that the object can be disposed before all references to it dies. The interface only says that.
But, the common all-purposes implementation (the Dispose pattern) says that:
Dispose() methods calls a virtual method Dispose that receives a boolean (true) and then calls GC.SuppressFinalize(this) and the destructor calls Dispose(false).
So, if you want your code to have somme implementation, you will at least need to implement a class (say MyDisposable) that implements IDisposable (so the using keyword can work with it) and implements Dispose to call:
Dispose(true);
GC.SupressFinalize(this);
And then, you make only the Dispose(disposing) virtual.
You can even make your "only call once" approach inside the non-virtual Dispose().
|
|
|
|
|
I dont know if I'm misunderstanding, or if maybe i posted my qustion wrong...basicly im trying to figure out something like this (VB)
public interface ISomeInterface
sub DoSomeStuff()
end interface
now when a sub class implements this i want DoSomeStuff() to have code already in it
public class MyDoSomeStuffClass
implements ISomeInterface
private mCanDoStuff as boolean = true ***i want this to be generated***
public sub DoSomeStuff() Implements ISomeInterface.DoSomeStuff
***Start Generated***
if mCanDoStuff Then
msgbox("WoOT")
End If
***end generated***
end sub
end class
--
"Keyboard not found. Press < F1 > to RESUME. "
Source unknown (appears in many common BIOSes as a real error message)
|
|
|
|
|
Polymorpher wrote: ***i want this to be generated***
I would ask on the Visual Studio board[^]...
There's probably an easy way to make a macro or something
that does this....I have no experience with that.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It's impossible.
Interfaces only says: The method exist.
You can, of course, do:
IMyInterface
(with some methods)
BaseClassThatImplementsIMyInterface
A class with virtual methods that implements the interface and, so, can create the basic functionality.
You can also create a helper class.
For example:
IMyInterface -> MyMethod
If your class comes from some other base class, it can implement IMyInterface and, in MyMethod, call
MyInterfaceBasicImplementation.MyMethod()
And, finally, you can create extension methods using interfaces.
So, for example:
IDictionary has the TryGetValue method.
I implemented a method called GetValueOrDefault as an extension method. It is NOT virtual, but as the TryGetValue is, it is enough for me.
|
|
|
|
|
It's not impossible, IDisposable does it. There is a way to do it, im just trying to figure out what that way is.
--
"Keyboard not found. Press < F1 > to RESUME. "
Source unknown (appears in many common BIOSes as a real error message)
|
|
|
|
|
I think it is implemented using the CodeDOM. Visual Studio will be calling a custom code generator for inserting that snippet of code. Can't find it though. Found the stuff for generating the default constuctor code, typed datasets, and all sorts by using reflector, but not Dispose. Must be hidden away in the bowels of the framework.
A good article on using the CodeDOM can be found here[^]
|
|
|
|
|
Thanks!
--
"Keyboard not found. Press < F1 > to RESUME. "
Source unknown (appears in many common BIOSes as a real error message)
|
|
|
|
|
Hey,
I'm creating a .Net download library. Part of the reason I'm doing this is to learn more about mulithreading. I've run into some things now that I'm not really able to solve, and can't find answers to, since it's pretty specific. I think my problems could be resolved after 15 to 30 mins of help by someone experienced with the involved aspects. If anyone feels like helping me out, please contact me.
# Email: jeroendedauw at gmail dot com
# Skype: rts.bn.vs
# Xfire: bn2vs
# Msn: jeroendedauw at gmail dot com
# Google talk: jeroendedauw
Cheers!
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
Come on, you've been a member long enough to know how it works. Post a piece of code, describe the problem and get an answer.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Indeed. I know that. But if you try something a few times, at multiple locations, and it fails, you should think of changing tactics, no?
My problem is more then 3 lines of code, and I really think I can't post it all here. Furthermore, since I'm not really sure on how to solve my problem, I can't determine which are all the relevant parts.
Jeroen De Dauw
---
Forums ; Blog ; Wiki
---
70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!
|
|
|
|
|
jeroen de dauw wrote:
My problem is more then 3 lines of code, and I really think I can't post it all here
is sort of different from your OP,
jeroen de dauw wrote: I've run into some things now that I'm not really able to solve, and can't find answers to, since it's pretty specific
To be honest, you seem to be strugglng to even explain the problems, which does make it difficult to help. I can't honestly see anyone contacting you direct under any circumstances, but particularly as you haven't really explained what is wrong.
Anyway, good luck
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
hi all, i need to export lakhs of records to excel, if i use the following code means, it doesn't throws any error,
select top 50000 * from dbo.CustomerDetail
but instead if i use
select * from dbo.CustomerDetail (it contains more than 10lakhs of records), it throws me an error.... Significant loss of functionality - the workbook contains data in cells outside of the row and column limit. data beyond 256(IV) columns by 65,536 rows will not be saved.....
my need is, if i have a table, it contains 70,000 records, i need to export it to excel, at that time it should automatically split the datas to two worksheets (which means 65000 in sheet1 and remaining 5000 in sheet2)...
code snippet in vb.net:
Imports Microsoft.Office.Interop.Excel
Imports System.Data.SqlClient
Imports System.Threading
Public Class Form1
Dim dtstart As DateTime = DateTime.Now
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strUniqueParamId As String
strUniqueParamId = System.Guid.NewGuid().ToString
Dim xThread As New Thread(AddressOf excelcheck)
xThread.Name = strUniqueParamId
xThread.Start()
MessageBox.Show("Generating")
Timer1.Start()
Thread.Sleep(1700)
'MessageBox.Show(Environment.TickCount.ToString());
End Sub
Sub excelcheck()
' Create the Excel Application object
Dim excelApp As New ApplicationClass()
' Create a new Excel Workbook
Dim excelWorkbook As Workbook = excelApp.Workbooks.Add(Type.Missing)
Dim sheetIndex As Integer = 0
Dim col, row As Integer
Dim excelSheet As Worksheet
Dim sqlcon As New SqlConnection("server=SHRIGI104\SHRIUNO0301;database=Test;uid=sa;pwd=welcome3#;")
sqlcon.Open()
Dim ds As New DataSet
Dim Da As New SqlDataAdapter()
Dim sqlcmd As New SqlCommand
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.CommandText = "SampleExcel"
sqlcmd.Connection = sqlcon
Da.SelectCommand = sqlcmd
Da.Fill(ds)
sqlcon.Close()
' Copy each DataTable as a new Sheet
For Each dt As System.Data.DataTable In ds.Tables
sheetIndex += 1
' Copy the DataTable to an object array
Dim rawData(dt.Rows.Count, dt.Columns.Count - 1) As Object
' Copy the column names to the first row of the object array
For col = 0 To dt.Columns.Count - 1
rawData(0, col) = dt.Columns(col).ColumnName
Next
' Copy the values to the object array
For col = 0 To dt.Columns.Count - 1
For row = 0 To dt.Rows.Count - 1
rawData(row + 1, col) = dt.Rows(row).ItemArray(col)
Next
Next
' Calculate the final column letter
Dim finalColLetter As String = String.Empty
Dim colCharset As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim colCharsetLen As Integer = colCharset.Length
If dt.Columns.Count > colCharsetLen Then
finalColLetter = colCharset.Substring( _
(dt.Columns.Count - 1) \ colCharsetLen - 1, 1)
End If
finalColLetter += colCharset.Substring( _
(dt.Columns.Count - 1) Mod colCharsetLen, 1)
' Create a new Sheet
excelSheet = CType( _
excelWorkbook.Sheets.Add(excelWorkbook.Sheets(sheetIndex), _
Type.Missing, 1, XlSheetType.xlWorksheet), Worksheet)
excelSheet.Name = dt.TableName
' Fast data export to Excel
Dim excelRange As String = String.Format("A1:{0}{1}", finalColLetter, dt.Rows.Count + 1)
excelSheet.Range(excelRange, Type.Missing).Value2 = rawData
' Mark the first row as BOLD
CType(excelSheet.Rows(1, Type.Missing), Range).Font.Bold = True
excelSheet = Nothing
Next
' Save and Close the Workbook
excelWorkbook.SaveAs("C:\BCP\sss.xls", XlFileFormat.xlWorkbookNormal, Type.Missing, _
Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, _
Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)
excelWorkbook.Close(True, Type.Missing, Type.Missing)
excelWorkbook = Nothing
' Release the Application object
excelApp.Quit()
excelApp = Nothing
' Collect the unreferenced objects
GC.Collect()
GC.WaitForPendingFinalizers()
MessageBox.Show("Genearted Sucessfully")
Timer1.[Stop]()
Dim dtEnd As DateTime = DateTime.Now
Dim ts As TimeSpan = dtEnd - dtstart
MessageBox.Show("Mins:" + ts.Minutes.ToString() + "" + "Secs:" + ts.Seconds.ToString())
End Sub
End Class
Sample Stored Procedure:
USE [Test]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter PROCEDURE [dbo].[SampleExcel]
AS
BEGIN
select top 50000 * from dbo.CustomerDetail
select top 50000 * from dbo.CustomerDetail
select top 50000 * from dbo.CustomerDetail
select top 50000 * from dbo.CustomerDetail
select top 50000 * from dbo.CustomerDetail
select top 50000 * from dbo.CustomerDetail
END
GO
the above sp should be re-written as in single select statement
like "select * from dbo.CustomerDetail"....
pls need the help very soon...
modified on Thursday, December 10, 2009 6:42 AM
|
|
|
|
|
1. Having that much records in an excel file! Why?
2. Why are you using interop? You can connect to the excel file through OleDb Connection and export everything to it through one insert command.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Well, your choices are to change your proc to select all the data and put some loop method in your code to output 65,000 records per sheet and start a new sheet, OR use dynamic sql to generate the appropriate number of selects and then execute them within the stored proc. I assume your table has a unique key that you can use to control the selection of each 50,000 rows?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
You may want to do a little test first to see how much of your data you can actually fit in a WORKBOOK, not a worksheet.
Yeah, you're going to exceed the number of rows available in a single sheet, and that's handled with a bit of work on your part. But, you're bigger problem is that you're probably going to run Excel out of memory before you get through all of your customers.
The test is easy. Take a small sample of records from your database and export them to an Excel sheet. Then copy and paste those records over and over again filling up the sheet as much as possible. Then create a new sheet and paste the records into that, filling up the sheet as much as possible. I think you'll find that you run Excel out of memory fairly quickly and long before you get through all of your customers.
|
|
|
|
|
I'm not sure about the memory issues, as a powerful enough machine should solved that problem, however it sounds as if you are using Excel 2003.
Excel 2003 is limited to 65,536 rows by 256 columns per worksheet. The number of worksheets is only limited by available memory.
If you move to Excel 2007 you can go up the the limit of 1,048,576 rows by 16,384 column per worksheet, with the number of worksheets is limited by available memory.
So either loop and create multiple sheets, or upgrade to 2007. Either way ensure you have a shed-load of memory available.
Excel 2003 Limits[^]
Excel 2007 Limits[^]
|
|
|
|
|
How to retrieve an email using pop3??There is no class pop3 and what is the best method??
|
|
|
|
|
You could have tried this[^] first, and read through some of the suggestions available.
|
|
|
|
|
I have a generic class that I am trying to instantiate through a non-generic static method, but I am having some problems getting the type inference to work. Does anyone see some way to resolve this?
Public Class MirrorObservableCollection(Of T)
Inherits ObservableCollection(Of T)
Friend Sub New(ByVal base As IList(Of T), ByVal mirror As Func(Of T, T))
End Sub
End Class
Public NotInheritable Class MirrorObservableCollection
Private Sub New()
End Sub
Public Shared Function Create(Of TItem, _
TList As {INotifyCollectionChanged, _
IList(Of TItem)})( _
ByVal base As TList, _
ByVal mirror As Func(Of TItem, TItem)) _
As MirrorObservableCollection(Of TItem)
Return New MirrorObservableCollection(Of TItem)(base, mirror)
End Function
End Class
Dim mirror = Function(s As String) s.ToUpperInvariant()
Dim base = New ObservableCollection(Of String)()
Dim m1 = MirrorObservableCollection.Create(Of String, _
ObservableCollection(Of String))(base, mirror)
Dim m2 = MirrorObservableCollection.Create(base, mirror)
EDIT: I tried some other things and found a few ways to make it work. Mixing variables initialized with lambdas and generic inference is not good for your health.
Dim asFunc As Func(Of String, String) = Function(s) s.ToUpperInvariant()
Dim m3 = MirrorObservableCollection.Create(base, asFunc)
Dim m4 = MirrorObservableCollection.Create(base, Function(s As String) s.ToUpperInvariant())
Dim m5 = MirrorObservableCollection.Create(base, Function(s) s.ToUpperInvariant())
Poking around in Reflector shows that mirror is of type AnonymousDelegate(Of string, string) . For those that are interested, my conclusions about what is going on are:
m1) The compiler knows that it needs Func(Of string, string) and will wrap mirror accordingly.
m2) The compiler has not been able to figure out what type to use for TItem and thus if the annonymous delgate signature will match.
m3) The compiler is given a Func(Of string, string) which it will use to deduce that TItem is string and goes from there.
m4) The compiler is given a lambda that is string ->string . There is some voodoo magic to combine lambda signature generation with generic inference and it all works.
m5) The compiler is given a lambda that is ???->???. It cannot determine what type the parameter is and thus assumes object. The error actually given is that the lambda parameter type cannot be determined, but also mentions that base does not implement IList(Of Object) .
What surprises me most is that in neither of the error cases does it seem that the compiler was able to deduce TItem from base , which implements IList(Of String)
|
|
|
|
|
hi, i don't know much about .net framework programing, and i want to learn how to use it but i don't know if i can use c++ with it which is the programing language that i know, i know vb as well but i prefered c++, is there a posibility to use .net framework in pure c++ without using those languages like c#, j# and changing it's syntax like c++/cli and all that stuff or do i need a diferent compiler for that purpose,also want to know if i can mix c++ standard libraris with .net fwrk's ones thank you
|
|
|
|
|
Yes, choose a CLR project type and away you go...
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|