|
Hi,
I've finally manage to compile and execute the code as suggested:
Private Async Sub MassPointImageBox_Click(sender As Object, e As EventArgs) Handles MassPointImageBox.Click
MsgBox("Take a Picture")
Dim capture = New CameraCaptureUI()
capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg
capture.PhotoSettings.MaxResolution = CameraCaptureUIMaxPhotoResolution.HighestAvailable
Dim GetPhotoTask As Task(Of StorageFile) = capture.CaptureFileAsync(CameraCaptureUIMode.Photo).AsTask
Dim Photo As StorageFile = Await GetPhotoTask
If Photo Is Nothing Then
MsgBox("No picture taken")
Else
MsgBox(Photo.Path)
End If
End Sub
However, the camera app does not open, and photo is always nothing. AnyOne ever had this kind of issue with .CaptureFileAsync ?
Thanks
|
|
|
|
|
I am trying to let a user type in a textbox and process input as the typing occurs - but also want to make sure that the last characters typed (when the user finished typing) are processed - I want to have only 1 processing task running at any time - so I would probably need something like the below with an async semaphore, right?
Does someone have a hint towards the correct code snippet?
MainWindow XAML:
<Window x:Class="InputTaskQueue.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:behav="clr-namespace:InputTaskQueue.Behaviors"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<StackPanel Orientation="Vertical">
<TextBox Name="tbInput"
behav:TextChangedCommand.ChangedCommand="{Binding SearchCommand}"
HorizontalAlignment="Left" VerticalAlignment="Bottom"
Width="100" Height="20"/>
<TextBlock Text="{Binding SearchStringResult,UpdateSourceTrigger=PropertyChanged,Mode=OneWay}" Width="100" Height="100" />
</StackPanel>
</Window>
Text KeyUp Behavior Triggera command via binding:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
public static class TextChangedCommand
{
private static readonly DependencyProperty ChangedCommandProperty = DependencyProperty.RegisterAttached(
"ChangedCommand",
typeof(ICommand),
typeof(TextChangedCommand),
new PropertyMetadata(null, OnTextChangedCommandChange));
public static void SetChangedCommand(DependencyObject source, ICommand value)
{
source.SetValue(ChangedCommandProperty, value);
}
public static ICommand GetChangedCommand(DependencyObject source)
{
return (ICommand)source.GetValue(ChangedCommandProperty);
}
private static void OnTextChangedCommandChange(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
TextBox uiElement = d as TextBox;
if (uiElement != null)
{
uiElement.TextChanged -= OnText_Changed;
var command = e.NewValue as ICommand;
if (command != null)
{
uiElement.TextChanged += OnText_Changed;
}
}
}
private static void OnText_Changed(object sender, TextChangedEventArgs e)
{
TextBox uiElement = sender as TextBox;
if (uiElement == null)
return;
if (uiElement.IsEnabled == false)
return;
ICommand changedCommand = TextChangedCommand.GetChangedCommand(uiElement);
if (changedCommand == null)
return;
var item = uiElement.Text;
if (changedCommand is RoutedCommand)
{
(changedCommand as RoutedCommand).Execute(item, uiElement);
}
else
{
changedCommand.Execute(item);
}
}
}
ViewModel bond to MainWindow:
private string _SearchStrinResult;
public string SearchStringResult
{
get { return _SearchStrinResult; }
private set
{
if (_SearchStrinResult != value)
{
_SearchStrinResult = value;
NotifyPropertyChanged(() => SearchStringResult);
}
}
}
#endregion properties
#region methods
public ICommand SearchCommand
{
get
{
if (_SearchCommand == null)
{
_SearchCommand = new RelayCommand<object>((p) =>
{
string findThis = p as string;
if (string.IsNullOrEmpty(findThis) == true)
return;
SearchCommand_ExecutedAsync(findThis);
},
(p =>
{
return true;
})
);
}
return _SearchCommand;
}
}
private List<string> _Queue = new List<string>();
private static SemaphoreSlim SlowStuffSemaphore = new SemaphoreSlim(1, 1);
private async void SearchCommand_ExecutedAsync(string input)
{
_Queue.Add(input);
await SlowStuffSemaphore.WaitAsync();
try
{
if (_Queue.Count > 1)
{
_Queue.Remove(input);
return;
}
else
{
Console.WriteLine("Queue Count: {0}", _Queue.Count);
}
await createTask(input);
_Queue.Remove(input);
this.SearchStringResult = input;
}
catch (Exception exp)
{
Console.WriteLine(exp.Message);
}
finally
{
SlowStuffSemaphore.Release();
}
}
private Task createTask(string input)
{
return Task.Run(() =>
{
Console.WriteLine("searching:" + input);
System.Threading.Thread.Sleep(5000);
})
.ContinueWith((p) =>
{
});
}
modified 13-Oct-17 16:45pm.
|
|
|
|
|
The easier way is for the user to finish typing, and not run a new thread until he/she finished editing. I don't see any data being presented to the user during processing, so in effect it would be the same as simply waiting for the focus-change and start processing then.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
The statement System.Threading.Thread.Sleep(5000); is a mockup for the background processing - it might in reality be 1 second or half a econd long but should definetly be done while typing not after - I know it would be easier otherwise - but anyone can do easy 
|
|
|
|
|
Then no, a semophore is not enough; you're focussing on just having one thread - you should be focussing on returning (partially processed) variables. Cancelling a running thread (see backgroundworker for ideas) is not hard.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am not sure what you mean - did you see the Task.Run(() statement?
Could you be more ,specific about what would be enough. Is there an open source example where something like this is implemented somewhere?
|
|
|
|
|
Dirk Bahle wrote: I am not sure what you mean - did you see the Task.Run(() statement? Yup. It is running a task, but I don't see it returning any values to present to the user. That's what you're trying to achieve; run a task, show the results to the user, and rerun with new data if the user changes the input.
Dirk Bahle wrote: Could you be more ,specific about what would be enough. You already have a single task that is run on the correct moment, as you say. So all that would be lacking is the actual presentation of the results "so far", and a mechanism to cancel the previous workload.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I push keyboard characters onto a "Stack" (which is what you are using your "queue" for).
If my "stack worker" isn't running, it gets started; and does incremental searching over the internet; returning results to a listbox.
If the stack is empty, the worker stops. It simply gets started again when another character is pushed and it is not running. No semaphor or waiting.
(And I only use a few lines of "code-behind" for what amounts to "plumbing"; not a lot of "indirection").
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
OK, you use a pull pattern from the worker thread - thats another good concept - but if you use no synchronization (via semaphores) between your threads then an unlucky timimg (even if unlikely) could still produce hard to debug results - I think this is part of the reason why Rx got introduced (see other comment in this discussion)
- I'll have a look at the Rx sample projects and maybe you should too - but thanks for the suggestion - I realy appreciate a discussion like this because it opens up your mind to the host of possibilities
|
|
|
|
|
This type of thing is generally accomplished, in the world of XAML apps, using RX. Search for RX autocomplete samples to get an understanding of how to structure it.
This space for rent
|
|
|
|
|
|
Hi,
I am getting the error :
An unhandled exception of type 'System.AccessViolationException' occurred in System.Data.dll
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
when I am trying to read excel file in my Console Application, I am also researching and googling but not finding the appropriate answer that can fix. The error is happening at conn.Open() call, is it related to opening file, then is there any way I can just open the file in read mode and read the values from it because all I need is to read the file and output/write those values into PipeDelimited CSV file.
Here is the code that I have:
public static string ConvertXlsAndXlstToPipeDelimitedFile(string strSourceFilePath, bool isFirstRowColumnHeader, string sheetName)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
strSourceFilePath + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"";
OleDbConnection conn = null;
StreamWriter wrtr = null;
OleDbCommand cmd = null;
OleDbDataAdapter da = null;
string destinationFilePath = string.Empty;
conn = new OleDbConnection(strConn);
try
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
cmd = new OleDbCommand("SELECT * FROM [" + sheetName + "$]", conn); //"Sheet1"
cmd.CommandType = CommandType.Text;
da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
string strDirectory = (System.IO.Path.GetDirectoryName(strSourceFilePath));
if (!System.IO.Directory.Exists(strDirectory))
{
System.IO.Directory.CreateDirectory(strDirectory);
}
Path.GetFileNameWithoutExtension(strSourceFilePath);
destinationFilePath = (strDirectory + (@"\" + (Path.GetFileNameWithoutExtension(strSourceFilePath) + ".csv")));
wrtr = new StreamWriter(destinationFilePath);
int ColCount = 0; string rowString = "";
for (int y = 0; y < dt.Columns.Count; y++)
{
rowString += dt.Columns[y].ColumnName + "|";
}
wrtr.WriteLine(rowString);
for (int x = 0; x < dt.Rows.Count; x++)
{
rowString = "";
for (int y = 0; y < dt.Columns.Count; y++)
{
rowString += "\"" + dt.Rows[x][y].ToString() + "\"|";
}
wrtr.WriteLine(rowString);
}
if (File.Exists(destinationFilePath))
return destinationFilePath;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (conn != null)
{
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
conn.Dispose();
}
if (cmd != null)
{
cmd.Dispose();
}
if (da != null)
{
da.Dispose();
}
if (wrtr != null)
{
wrtr.Close();
wrtr.Dispose();
}
}
//MessageBox.Show("Done");
return string.Empty;
}
Can anybody please help me why am I getting that error and is there any fix for it? - Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
This is just like a NullPointerException, but it gets caught by a system library. You need to use your debugger to find the point in your code that leads to the error and see which parameter or variable contains an invalid address.
|
|
|
|
|
This error is happening at conn.Open(); statement, it says like file is locked, when I see actually file is not locked or used by anything. Is there any way if File is used still we can read from it. Only this app is saying like that. when I use the same code in another app it is able t read everything fine. Very goofy like things are happening. Not really able to do anything. This is required to run in all possible situations without interruption.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Not sure how that relates to a memory access violation. I think you need to look deeper.
|
|
|
|
|
Definitely I can look into it if you can just give me direction to proceed my friend, really not understanding where is going wrong. Even if the File locked can we just read or close it explicitly to it? Any direction or hint can help me my friend.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
As I mentioned before, to find the access violation you need to catch it in the debugger and look at the stack trace to find where it originated in your code. I think you need to spend more time getting familiar with your debug tools.
|
|
|
|
|
Ok thanks my friend
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
It got fixed just saying if somebody is going through the same, only one thing I changed was I have placed the file in a different location than C drive, could it be the problem? Yes maybe I guess so, but that was the only thing I changed and its Working. Because its saying memory not readable probably that could be the issue - forgive me but its just my guess . Thanks for all you support and taking time my friend.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
That was the crucial piece of evidence you did not mention.
|
|
|
|
|
Post the (complete) exception and stacktrace
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
It got fixed just saying if somebody is going through the same, only one thing I changed was I have placed the file in a different location than C drive, could it be the problem? Yes maybe I guess so, but that was the only thing I changed and its Working. Because its saying memory not readable probably that could be the issue - forgive me but its just my guess . Thanks for all you support and taking time my friend.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Some locations have more rights than others, and not every application or library handles them nice.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I am trying to import Date values of Pipe-Delimited file into Sql Table, I am getting the following error
Error: 0xC0049064 at Populate Stage, Derived Column [97]: An error occurred while attempting to perform a type cast.
Error: 0xC0209029 at Populate Stage, Derived Column [97]: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR. The "Derived Column" failed because error code 0xC0049064 occurred, and the error row disposition on "Derived Column.Outputs[Derived Column Output].Columns[Payment Due Date]" specifies failure on error. An error occurred on the specified object of the specified component. There may be error messages posted before this with more information about the failure.
Error: 0xC0047022 at Populate Stage, SSIS.Pipeline: SSIS Error Code DTS_E_PROCESSINPUTFAILED. The ProcessInput method on component "Derived Column" (97)
failed with error code 0xC0209029 while processing input "Derived Column Input" (98). The identified component returned an error from the ProcessInput method.
The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running. There may be error messages posted before this with more information about the failure.
The Following is the expression I am using for the derived Column
(DT_DATE)(SUBSTRING([Date Posted],1,4) + "-" + SUBSTRING([Date Posted],5,2) + "-" + SUBSTRING([Date Posted],7,2))
I am also trying my best searching online, can anybody please let me know if I am missing anything. Thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
indian143 wrote:
(DT_DATE)(SUBSTRING([Date Posted],1,4) + "-" + SUBSTRING([Date Posted],5,2) + "-" + SUBSTRING([Date Posted],7,2))
Might I suggest the first thing to do is to look at the data being used to get those substrings. According to your code above do they make up a valid date?
|
|
|
|